开发者

getting xml child in javascript

I'm trying to get to to the items child in XML using javascript.

The rss file is: Can i use dot syntax? item.title? I'mg etting undefined in the code below

<item> <title><link>

$(document).ready(function(){ alert = console.log;

  var ns = {
    init : function(){
        $.ajax({
            url: '/calendar/RSSSyndicator.aspx?type=N&number=15&category=8-0%2c4-0%2c6-0%2c10-0%2c7-0%2c17-0%2c16-0%2c9-0%2c5-0%2c3-0%2c2-0&department=3&numdays=31&ics=Y&rsstitle=Annandale+-+Event+Listing&rssid=11',
            success: this.loaded          开发者_StackOverflow      
        });
    }, 

    loaded: function(data){
        // Get access to the events id in the DOM
        var events = document.getElementById('events');

        // Get item from the RSS document
        var items = data.getElementsByTagName('item');
    alert('test');



    }

}



ns.init();

});


The easiest way to debug issues like this is to load up the page in firefox after installing the FireBug plugin. In this plugin, you can set a breakpoint, and then inspect the items variable and see what properties and structure the object has.

Alternatively, if you are open to it, you can load up the XML into a jQuery object and then use those facilities to navigate the DOM.


No, unless you're using E4X you can't use dot notation to navigate an XML DOM in JavaScript. You'll have to use standard DOM: getElementsByTagName("title"), childNodes etc.

E4X does let you navigate XML as though it were a JavaScript object tree, but of the main browsers it is only supported in Firefox.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜