开发者

AJAX & Javascript & XML: adding DOM elements to array not working

开发者 https://www.devze.com 2023-02-18 14:38 出处:网络
I am fetching some XML from Flickr and want to parse it based on DOM. can\'t get my code to work with the following:

I am fetching some XML from Flickr and want to parse it based on DOM. can't get my code to work with the following:

...
if (this.responseXML != null)
    {
        content = this.responseText.getElementsByTagName('content')
        for (i = 0 ; i < content.length ; i++)
        {
            out += content[i].childNodes[0].nodeValue + '<br />'
        }
        document.getElementById('info').innerHTML = out
        }
...

this however returns the full content of the call:

...
if (this.responseXML != null)
    {
        document.getElementById('info').innerHTML =
            this.responseText
            }
...

which leads me to think that my AJAX code is correct but that i'm doing something wrong in the parsing code

Note: this is relat开发者_如何学JAVAed another post althought he problem is a different one


The problem seems to be that you're given a string rather than an XML DOM object. In order to create a XML DOM Object, you'll need to parse the XML string. This stackoverflow thread has some good code and discussion as to what the best way to parse the XML might be.

0

精彩评论

暂无评论...
验证码 换一张
取 消