Reputation: 4543
in my system, i had to move a big javascript ajax system to seam. i got that to work correctly by adding
xml = (new DOMParser()).parseFromString(s, "text/xml");
now my problem is it has just come to my attention that the domparser is for some reason changing the order of the xml elements. ive narrowed it down, it has to be this. since these elements are sorted in a specific order when it leaves the server, the dom parser reorganizing is not a good thing. anyone seen this? anyone know how to fix it?
Upvotes: 1
Views: 1443
Reputation: 4543
For anyone that is still is having this problem, i solved it by writing my own XML parser. i stopped using DomParser all together and since this time, i have changed over to json which doesn't have the problem at all.
thanks
Upvotes: 0
Reputation: 13
I've run across this issue in IE 9 RC 1 Standards mode trying to get around another issue (the XMLHttpRequest object returning an MSXML ActiveX object even when in Standards mode. Feature detection sees the DOMParser and the two documents are not compatible so I figured using the DOMParser would do the trick)
Sample code that reproduces the issue in IE 9 RC 1:
var sXML = "<TEST ID=\"124\" TITLE=\"TitleValue\" DATE=\"2011-02-24T00:00:00\" STATUS=\"Processing\" EMPNAME=\"Smith, Sam\" STATUSCODE=\"P\" ROWNUM=\"1\" />";
var dpParser = new DOMParser();
var xdDoc = dpParser.parseFromString(sXML, "text/xml");
var xsSerialize = new XMLSerializer();
var sNewXML = xsSerialize.serializeToString(xdDoc);
alert("Original XML:\n" + sXML + "\n\nNew XML:\n" + sNewXML);
The alert's output...
Original XML:
<TEST ID="124" TITLE="TitleValue" DATE="2011-02-24T00:00:00" STATUS="Processing" EMPNAME="Smith, Sam" STATUSCODE="P" ROWNUM="1" />
New XML:
<TEST ROWNUM="1" STATUSCODE="P" EMPNAME="Smith, Sam" STATUS="Processing" DATE="2011-02-24T00:00:00" TITLE="TitleValue" ID="124" />
Update: I had filed a bug report with Microsoft for IE 9 regarding this issue and they have resolved it as 'by design'.
If you expect your XML attributes in a certain order when using the DOMParser.parseFromString function in IE 9, you will want to grab the attributes explicitly rather than simply iterating over them.
The following was the bug report: https://connect.microsoft.com/IE/feedback/details/645091/domparser-parsefromstring-in-ie-9-rc-1-rearranges-the-attributes-of-the-xml-node-passed-in
Upvotes: 1
Reputation: 324567
I would be extremely surprised if this is the case. Node order is defined as being significant in XML and I can't believe any browser's implementation of DomParser
would fail to respect it. I suggest you look again at your code.
Upvotes: 0