用jquery或其他方式将字符串转换为xml doc [英] convert a string to xml doc with jquery or the other way round
本文介绍了用jquery或其他方式将字符串转换为xml doc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将字符串转换为xml文档以读取大量节点或使用jquery附加新节点,然后在此之后再次将其转换回字符串.谁能帮助我. 这是我的代码的片段
i am trying to convert a string to an xml document to read the verious nodes or to append a new node with jquery and there after convert it back to a string again. can anyone help me on the please. this is a snippet of my code
xmldoc.find('ROOT').append(
'<USER><ENAME>'+ $(this).find('ENAME').text() +
'</ENAME><OPERATOR>'+$(this).find('OPERATOR').text() +
'</OPERATOR><PNR>'+$(this).find('PNR').text() +
'<PNR></USER>'
);
if (window.ActiveXObject) {
xmldocStr = xmldoc.xml;
}
// code for Mozilla, Firefox, Opera, etc.
else {
xmldocStr = (new XMLSerializer()).serializeToString(xmldoc);
推荐答案
将其包装在jQuery对象中.
Wrap it in a jQuery object.
var t = $('<foo><bar>something</bar></foo>');
//loop over 'bar' nodes
t.find('bar').each(function () {
alert($(this).text());
});
并将其转换回字符串:
//then convert it back to a string
//for IE
if (window.ActiveXObject) {
var str = t.xml;
alert(str);
}
// code for Mozilla, Firefox, Opera, etc.
else {
var str = (new XMLSerializer()).serializeToString(t);
alert(str);
}
这篇关于用jquery或其他方式将字符串转换为xml doc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文