如何解析Chrome 24和jQuery 1.8.2中的命名空间XML? [英] How to parse namespace XML in Chrome 24 and jQuery 1.8.2?
问题描述
我试图解析以下XML:
< catalog>
< ns:book>
< author>作者< / author>
< / ns:book>
< / catalog>
我已经进行了大量研究,发现了以下(过去)解决方案,但它们当前都不支持Chrome 24与jQuery 1.8一起使用
$ b $ $ p $ $ $ $ c $ $ xml .find(ns \\:book)。each(function()
{
$(#output)。append($(this).find(author)。text()+< br />);
} );
也不是
$(xml).find(book)。each(function()
{
$(#output)。append($(this).find(author ).text()+< br />);
});
也不是
$(xml).find([nodeName = ns:book])。each(function()
{
$(#output)。append($(this) .find(author)。text()+< br />);
});
在我的研究中,似乎这主要是一个chrome问题,而不是jQuery问题。有没有公认的解决方案?是否有更好的js库用于XML解析?
我今天刚刚遇到同样的问题。使用jQuery 1.8.3和Chrome 23我注意到了两种情况:
// Data是一个字符串表示XML
var data =< catalog>< ns:book>< author> Author< / author>< / ns:book>< / catalog>;
案例1
//案例1
var xml = $ .parseXML(data);
// xml是一个XmlDocument
$(xml).find(book);
// $(xml)是一个Document
//直接运行,似乎无法使用命名空间。
案例2.
var xml = $(data);
// xml是一个对象
$(xml).find('ns \\:book')
//正常工作
I am trying to parse the following XML:
<catalog>
<ns:book>
<author>Author</author>
</ns:book>
</catalog>
I have researched extensively and found the following (past) solutions and none of them currently work in Chrome 24 with jQuery 1.8
$(xml).find("ns\\:book").each(function()
{
$("#output").append($(this).find("author").text() + "<br />");
});
nor
$(xml).find("book").each(function()
{
$("#output").append($(this).find("author").text() + "<br />");
});
nor
$(xml).find("[nodeName=ns:book]").each(function()
{
$("#output").append($(this).find("author").text() + "<br />");
});
In my research, it would seem that this is primarily a chrome issue and not a jQuery issue. Is there an accepted solution? Is there a better js library to use for XML parsing?
I just hit the same issue today. With jQuery 1.8.3 and Chrome 23 I've noticed 2 cases:
//Data is a string representing XML
var data = "<catalog><ns:book><author>Author</author></ns:book></catalog>";
Case 1
//Case 1
var xml = $.parseXML(data);
//xml is a XmlDocument
$(xml).find("book");
//$(xml) is a Document
//works directly, can't seem to be able to use namespace.
Case 2.
var xml = $(data);
//xml is an Object
$(xml).find('ns\\:book')
//works just fine
这篇关于如何解析Chrome 24和jQuery 1.8.2中的命名空间XML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!