The AjxUtil.xmlToJs method can't handle namespaces in attribute tags.
The response of a SOAP request:
Code:
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<env:Body>
<n1:FindAllProductsResponse xmlns:n1="urn:ActionWebService" env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<return n2:arrayType="xsd:int[4]" xmlns:n2="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="n2:Array">
<item>
1
</item>
<item>
2
</item>
<item>
3
</item>
<item>
4
</item>
</return>
</n1:FindAllProductsResponse>
</env:Body>
</env:Envelope> The result after it is been processed by AjxUtil.xmlToJs (I stripped the whitespaces where I also are having problems with):
Code:
{
Body:{
FindAllProductsResponse: {
xmlns:n1:"urn:ActionWebService",
env:encodingStyle: "http:\/\/schemas.xmlsoap.org\/soap\/encoding\/",
return:{
n2:arrayType:"xsd:int[4]",
xmlns:n2:"http:\/\/schemas.xmlsoap.org\/soap\/encoding\/",
xsi:type:"n2:Array",
"",
item:{
"1"
},
item:{
"2"
},
item:{
"3"
},
item:{
"4"
}
}
}
}
} If you use the eval function on this then it obviously brakes on xmlns:n1 and so on.
I wrote a little fix:
Code:
AjxUtil.xmlToJs =
function(node, omitName) {
if (node.nodeType == AjxUtil.TEXT_NODE)
return ['"', node.data, '"'].join("");
var name = node.name ? node.name : node.localName;
if (node.nodeType == AjxUtil.ELEMENT_NODE) {
var text = omitName ? "{" : [name, ":{"].join("");
var needComma = false;
if (node.attributes ) {
for (var i = 0; i < node.attributes.length; i++) {
var attr = node.attributes[i];
if (attr.name == "xmlns") continue;
if (needComma) text += ",";
var value = AjxUtil.isNumeric(attr.value) ? attr.value : AjxUtil.jsEncode(attr.value);
var attr_name = attr.name
var indexdblp = attr_name.indexOf(":")
if(indexdblp != -1 ) attr_name = attr_name.substr(indexdblp+1)
text = [text, attr_name, ':', value].join("");
needComma = true;
}
}
if (node.hasChildNodes()) {
var cnodes = new Object();
var hasChild = false;
for (var i = 0; i < node.childNodes.length; i++) {
var child = node.childNodes[i];
var cname = child.name ? child.name : child.localName;
var isAttr = AjxUtil.NODE_IS_ATTR[cname] ||
(name == "content" && parent.name == "note");
if (isAttr) {
if (needComma) text += ",";
text = [text, cname, ':', AjxUtil.jsEncode(child.textContent)].join("");
needComma = true;
} else {
if (!cnodes[cname])
cnodes[cname] = new Array();
cnodes[cname].push(child);
hasChild = true;
}
}
if (hasChild && needComma) {text += ","; needComma = false;}
for (var cname in cnodes) {
if (needComma) {
text += ",";
needComma = false;
}
var repeats = AjxUtil.NODE_REPEATS[cname] ||
(cname == "mp" && name == "mp");
if (repeats) text += cname + ":[";
var clist = cnodes[cname];
for (var i = 0; i < clist.length; i++) {
if (needComma) text += ",";
text += AjxUtil.xmlToJs(clist[i], repeats);
needComma = true;
}
if (repeats) text += "]";
}
}
text += "}";
}
return text;
} Somewhere in the code there are the lines:
var indexdblp = attr_name.indexOf(":")
if(indexdblp != -1 ) attr_name = attr_name.substr(indexdblp+1)
text = [text, attr_name, ':', value].join("");
They take care of the namespaces by removing them.