开发者

Traversing an XML file using YUI 2.8 library

I have a requirement to parse/traverse an XML file using the YUI 2.8 library. From the YUI's manual page of DataSource, I could get i开发者_开发问答nfo about how to get the XML file using XHRDataSource and then set the response type and response schema (understood it after so many readings :P ).

But, after setting up the DataSource, I don't know what to do to fetch data from my XML file? That page doesn't seem to provide any example on that. can anyone explain the procedure to parse the XML file using DataSource?


After setting up your DataSource, call sendRequest() with a callback function to retrieve data from your XML file.

var myDataSource = new YAHOO.util.XHRDataSource("./myxml");
myDataSource.responseType = YAHOO.util.DataSource.TYPE_XML;
myDataSource.responseSchema = {
    resultNode: "book",
    fields: ["title","author","year"]
};
ds.sendRequest(null, {
    success: function(request, response) {
        var results=response.results,
            i=0,
            l=results.length;

        for(; i<l; i++) {
            YAHOO.log(results[i].title);
        }
    }
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜