The AjxUtil.xmlToJs method can't handle namespaces in attribute tags.
The response of a SOAP request:
http://www.w3.org/2001/XMLSchema" xmlns:env=http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance">
http://schemas.xmlsoap.org/soap/encodin ... /encoding/">
http://schemas.xmlsoap.org/soap/encodin ... /encoding/" xsi:type="n2:Array">
1
2
3
4
The result after it is been processed by AjxUtil.xmlToJs (I stripped the whitespaces where I also are having problems with):
{
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:
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
var attr = node.attributes;
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
var child = node.childNodes;
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
if (needComma) text += ",";
text += AjxUtil.xmlToJs(clist, 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.
AjxUtil.xmlToJs can't handle namespaces
-
- Posts: 13
- Joined: Fri Sep 12, 2014 9:55 pm
AjxUtil.xmlToJs can't handle namespaces
I created Web Services in Ms.Net and the result return as below:
http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi=http://www.w3.org/2001/XMLSchema-instan ... a-instance" xmlns:xsd=http://www.w3.org/2001/XMLSchema">
http://www.profrtgroup.com/webservices/" />
it failed to create xmldoc from the above message.
Then i remove , it success....
This occurs only in IE, Firefox is fine.
Help please...
http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi=http://www.w3.org/2001/XMLSchema-instan ... a-instance" xmlns:xsd=http://www.w3.org/2001/XMLSchema">
http://www.profrtgroup.com/webservices/" />
it failed to create xmldoc from the above message.
Then i remove , it success....
This occurs only in IE, Firefox is fine.
Help please...
AjxUtil.xmlToJs can't handle namespaces
What kind of error do you get when you try with the header?
-
- Posts: 13
- Joined: Fri Sep 12, 2014 9:55 pm
AjxUtil.xmlToJs can't handle namespaces
This will not cause an error from CreateXmlFromString
But error occurred in _check function.
the doc will retrun with 2 childnodes...
one for
and another one for
_check function will check for only valid return is only one childnode for doc.
But error occurred in _check function.
the doc will retrun with 2 childnodes...
one for
and another one for
_check function will check for only valid return is only one childnode for doc.
AjxUtil.xmlToJs can't handle namespaces
I also had problems with the _check method. Because the AJAX xml methods don´t ignore whitespaces there are more elements in the xml document then _check expects. I already opend a tread about that problem.
Maybe you can right a fix for the problem and share the code with us.
Maybe you can right a fix for the problem and share the code with us.
-
- Posts: 13
- Joined: Fri Sep 12, 2014 9:55 pm
AjxUtil.xmlToJs can't handle namespaces
The main issue for me is the problem occurs only in IE.
AjxUtil.xmlToJs can't handle namespaces
Somebody opend a new thread with the same problem (or is it?). See http://www.zimbra.com/forums/showthread.php?t=638 for your answer.