将XML jQuery对象转换为字符串 [英] convert an XML jQuery Object to String

查看:498
本文介绍了将XML jQuery对象转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个上传的xml文件,我通过 var $ ts = $ .parseXML(filecontents)


$ b使用jQuery $ b

通过利用以下内容在XML文档中查找对象时,我试图将其转换回原始源:

  $ ( '< DIV>')。追加($ ts.find( '对象')克隆()。)HTML(); 

在chrome中,这个工作非常好,我得到了原始文档中的输出结果。在firefox中,它按字母顺序重新排列元素的属性。

由于我将这个输出散列化,所以我需要它与输入相同。这是可能的强制执行,或者我用不同的方法走过这个xml文档?

改为 XMLSerializer API:

  var foo = $ ts.find(Object)。get(0); 
var serializer = new XMLSerializer();
var original = serializer.serializeToString(foo);


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?

解决方案

Use the XMLSerializer API instead:

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

这篇关于将XML jQuery对象转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆