Is this a mistake while parsing XML using jQuery?

OK I’ll try to explain it as simple as possible,

I am trying to parse the XML that I get through a web service using jQuery. Everything does as it should, until I noticed that for the love of God I can not make out the node, which is called the "image". a long story is short (and after 2 hours). I noticed that the problem is in TAG NAME. Obviously, an “image” is a reserved word or something like that ???

Here is a demo; Firstly, I mimicked an xml that has an "image" node and will not show any results. Secondly, I modeled SAME xml, the MOST parsing, I just renamed the "image" to "image1" and it WORKS. See an example here: http://jsbin.com/evinah/1/edit

So it’s obvious that I can’t change the web service, it’s not in my domain. How to get the value of "image" using jQuery?

Thank you for your responses.

+3
source share
3 answers

You should use $.parseXMLif you are processing a string, this will return a valid valid XML document that can be used with jQuery.

$($.parseXML(xml)).find('item').each(function(i, e){
  alert($(e).children('image').text());
});

(see here).

AJAX, dataType xml.


, $(xml) $.parseXML, <image>, <image> <img> DOM. , <img> , XML.

<img> <image> <img> vs <image> HTML.

+2

, , , "" image.

XML- jQuery, DOM XML. DOM , , HTML.

, , root:

> var e = document.createElement('root');
  <root></root>

console.log(e) , , HTMLUnknownElement, .

image:

> var e = document.createElement('image');
  <img>

-? <image></image>? , image img. HTMLImageElement.

, .children('img').text(), , img . , , :

<root>
    <item>
        <img>
        image link
    </item>
    <item>
        <img>
        image link2
    </item>
</root>

img, .

+3

The function is $not intended for XML parsing. You should use $.parseXMLand then wrap this in a jQuery: object $($.parseXML(...)). In fact, there is also a special function for HTML $.parseHTML. A function $called with a string must be used with either a selector or a simple string "<tag>".

+2
source

All Articles