用jQuery解析此XML的最佳方法 [英] Best way to parse this XML with jQuery
本文介绍了用jQuery解析此XML的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<?xml version="1.0" encoding="UTF-8" ?>
<BMC_Impact_Manager version="1.0">
<IMPACT_EVENT>
<EVENT>
<date_reception>1279568162</date_reception>
</EVENT>
<EVENT>
<date_reception>1279568162</date_reception>
</EVENT>
<EVENT>
<date_reception>1279568102</date_reception>
</EVENT>
<EVENT>
<date_reception>1279567862</date_reception>
</EVENT>
<EVENT>
<date_reception>1279567836</date_reception>
</EVENT>
</IMPACT_EVENT>
我们将XML输出更改为如下所示...所以现在我不再需要帮助了……谢谢!
We changed the XML output to look like this... so now I no longer need help... Thanks though!
推荐答案
使用适当的XML解析器.
Use a proper XML parser.
// http://www.w3schools.com/dom/dom_parser.asp
function parseXML(text) {
var doc;
if(window.DOMParser) {
var parser = new DOMParser();
doc = parser.parseFromString(text, "text/xml");
}
else if(window.ActiveXObject) {
doc = new ActiveXObject("Microsoft.XMLDOM");
doc.async = "false";
doc.loadXML(text);
}
else {
throw new Error("Cannot parse XML");
}
return doc;
}
然后将所有日期接收标签的值都获取为
Then get all date reception tag values as
var xml = parseXML(xmlString);
$(xml).find('date_reception').each(function() {
console.log(this.text());
});
这篇关于用jQuery解析此XML的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文