views:

27

answers:

1

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 info 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?

+1  A: 

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);
        }
    }
});
Jenny Donnelly