YUI Library JavaScript DHTML



    
Local XML Data

/*margin and padding on body element
  can introduce errors in determining
  element position and are not recommended;
  we turn them off as a foundation for YUI
  CSS treatments. */
body {
  margin:0;
  padding:0;
}











Local XML Data



  

This DataTable is populated with XML data from a webservice that is held in local memory in the
JavaScript variable xmlDoc.


      




YAHOO.util.Event.addListener(window, "load", function() {
    YAHOO.example.Local_XML = function() {
        var myDataSource, myDataTable;
        
        var connectionCallback = {
            success: function(o) {
                var xmlDoc = o.responseXML;
                var myColumnDefs = [
                    {key:"Title", label:"Name", sortable:true, formatter:"link"},
                    {key:"Phone"},
                    {key:"City"},
                    {key:"AverageRating", label:"Rating",formatter:YAHOO.widget.DataTable.formatNumber, sortable:true}
                ];
                myDataSource = new YAHOO.util.DataSource(xmlDoc);
                myDataSource.responseType = YAHOO.util.DataSource.TYPE_XML;
                myDataSource.responseSchema = {
                    resultNode: "Result",
                    fields: ["Title","Phone","City",{key:"AverageRating",parser:"number"},"ClickUrl"]
                };
                myDataTable = new YAHOO.widget.DataTable("localxml", myColumnDefs, myDataSource);
            },
            failure: function(o) {
            }
        };
        var getXML = YAHOO.util.Connect.asyncRequest("GET",
                "yui_2.7.0b-assets/datatable-assets/php/ylocal_proxy.php?query=pizza&zip=94089&results=10",
                connectionCallback);
                
        return {
            oDS: myDataSource,
            oDT: myDataTable
        };
    }();
});



   
  
yui_2.7.0b.zip( 4,431 k)