I have an uploaded xml file that I'm perusing using jQuery via var $ts = $.parseXML(filecontents)
I have attempted to convert back to the original source when locating objects within the XML Document by utilising:
$('<div>').append($ts.find('Object').clone()).html();
In chrome, this works absolutely fine and I get the output as it looks in the original document. In firefox, it reorders the attributes of elements alphabetically.
Since I'm hashing this output, I need it to be the same as the input. Is this possible to enforce at all, or am I better with a different method of walking through this xml document?
I have an uploaded xml file that I'm perusing using jQuery via var $ts = $.parseXML(filecontents)
I have attempted to convert back to the original source when locating objects within the XML Document by utilising:
$('<div>').append($ts.find('Object').clone()).html();
In chrome, this works absolutely fine and I get the output as it looks in the original document. In firefox, it reorders the attributes of elements alphabetically.
Since I'm hashing this output, I need it to be the same as the input. Is this possible to enforce at all, or am I better with a different method of walking through this xml document?
Share Improve this question edited Mar 5, 2014 at 1:54 Paul Sweatte 24.6k7 gold badges131 silver badges268 bronze badges asked Jun 24, 2013 at 10:19 jhogendornjhogendorn 6,1403 gold badges28 silver badges36 bronze badges 1- possible duplicate of Convert String to XML Document in JavaScript – Larry Battle Commented Apr 15, 2014 at 22:03
1 Answer
Reset to default 9Use the XMLSerializer API instead:
var foo = $ts.find("Object").get(0);
var serializer = new XMLSerializer();
var original = serializer.serializeToString(foo);