最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - convert an XML jQuery Object to String - Stack Overflow

programmeradmin1浏览0评论

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
Add a ment  | 

1 Answer 1

Reset to default 9

Use the XMLSerializer API instead:

var foo = $ts.find("Object").get(0);
var serializer = new XMLSerializer(); 
var original = serializer.serializeToString(foo);
发布评论

评论列表(0)

  1. 暂无评论