Why can't jQuery parse specific xml nodes?

I am calling a webpage through ajax. Part of his answer is a small block of XML.

I tried to parse it, but jQuery only seems to find some of the nodes. For instance:

<aaa>
   <text>bbb</text>
   <image>test</image>
</aaa>

It finds the text just fine, but does not find the node image.

But if I change the spelling from "image" to "zimage", she finds it. Is the word "image" reserved when parsing XML through jQuery?

My jQuery code is very simple ...

$(data).find("zimage").each(function() {
    alert("node found");
});

This code works, but when I use it ...

$(data).find("image").each(function() {
    alert("node found");
});

He never finds anything.

+3
source share
3 answers

What version of jQuery are you using? It seems that jQuery 1.5 has a function parseXML():

var data="<aaa><text>bbb</text><image>test</image></aaa>";
var xmlDoc = jQuery.parseXML(data);
var $xmlDoc = jQuery(xmlDoc);

$xmlDoc.find("image").each(function() {
   alert("node found"); //this alert pops up because find() returns [image]
});

jQuery, 1.5, parseXML(). , - XML, DOM, XML. , , , , .

+3

javascript "" :

<aaa><text>bbb</text><img>test</aaa>

, :

var xml = "<aaa><text>bbb</text><image>test</image></aaa>";
var data = $("<div />", { html: xml });

data.find("img").each(function() {
    alert("node found");
});

XML , XML. , .

+1

xml DOM, jQuery. jQuery xml, DOM, .

, DOM XML: http://outwestmedia.com/jquery-plugins/xmldom/

+1

All Articles