3

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?

Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265
jhogendorn
  • 5,931
  • 3
  • 26
  • 35
  • possible duplicate of [Convert String to XML Document in JavaScript](http://stackoverflow.com/questions/1290321/convert-string-to-xml-document-in-javascript) – Larry Battle Apr 15 '14 at 22:03

1 Answers1

9

Use the XMLSerializer API instead:

var foo = $ts.find("Object").get(0);
var serializer = new XMLSerializer(); 
var original = serializer.serializeToString(foo);
Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265