Which or which plugin in jquery should I use to populate the html table with the contents of the xml file?

I have a requirement to display data from an XML file from the server (the file path is something like files/client.xml) to an html or datagrid table, which plugin, or rather what should I use, so that it has variable pagination, filtering and css table settings . Any suggestions will help, a small example should be a plus for me :) Thanks

Note : my xml structure is fixed.

<?xml-stylesheet type="text/xsl" href="csmclientiir.xsl"?>
<csmclient product="abc"   date="4/26/11 2:05 PM">
<system>
    <osname>Linux
    </osname>
    <hostname>AbhishekNix
    </hostname>
    <release>2.6.18-128.el5
    </release>
    <filesystem>
        <file mount='/home/hp1' home='(innfs2:/vol/home/shome/home/hp1)' total='1717567488' free='644306780' used='1073260708' percentage='62' />
        <file mount='/home/par21' home='(innfs2:/vol/home/shome/home/par21)' total='1717567488' free='644306780' used='1073260708' percentage='62' />
        <file mount='/home/h231' home='(innfs2:/vol/home/shome/home/h231)' total='1717567488' free='644306780' used='1073260708' percentage='62' />
        <file mount='/home/avallin1' home='(innfs2:/vol/home/shome/home/avallin1)' total='1717567488' free='644306780' used='1073260708' percentage='62' />
        <file mount='/home/park' home='(innfs2:/vol/home/shome/home/park)' total='1717567488' free='644306780' used='1073260708' percentage='62' />
        <file mount='/home/sp1' home='(innfs2:/vol/home/shome/home/sp1)' total='1717567488' free='644306780' used='1073260708' percentage='62' />
        <file mount='/home/ganga1' home='(innfs2:/vol/home/shome/home/ganga1)' total='1717567488' free='644306780' used='1073260708' percentage='62' />
        <file mount='/home/nbp1' home='(innfs2:/vol/home/shome/home/nbp1)' total='1717567488' free='644306780' used='1073260708' percentage='62' />
    </filesystem>
</system>
<product>
    <showtime>Tue Apr 26 14:05:23 2011
    </showtime>
</product>
</csmclient>

Update using a working solution

Since it does not accept the attribute .. as I would like to get here mount, freeetc. Here is what I did in jqGrid for the above xml.

var i=0;
var filesystem=[];
$(xml).find('file').each(function(){ 
    var row={};
    row.id=i++;
    row.total=$(this).attr('total');
    row.free=$(this).attr('free');
    row.used=$(this).attr('used');
    row.percentage=$(this).attr('percentage');
    filesystem.push(row);
});


$('#detailTable').empty();
$('<div width="100%">')
.attr('id','diskUsageSpan')
.html('<div class="titleBlue">Configuration&gt;System&gt;Disk Usage</div>'+
        '<table id="list1" width="100%"></table>'+
        '<div id="gridpager"></div>'+
    '</div>')       
.appendTo('#detailTable');  



jQuery("#list1").jqGrid({
    datatype: "clientSide",
    height: 250,
    colNames:['id','Total Space','Free Space', 'Used Space', 'Used Percentage'],
    colModel:[
        {name:'id',index:'id', width:90, align:"right"},
        {name:'total',index:'total', width:90, align:"right"},
        {name:'free',index:'free', width:90, align:"right"},
        {name:'used',index:'used', width:90, align:"right"},
        {name:'percentage',index:'percentage', width:120, align:"right"}
    ],
    pagination:true,
    pager : '#gridpager',
    rowNum:10,
    scrollOffset:0,
    height: 'auto',
    autowidth:true,
    viewrecords: true,
    gridview: true,
    edit:false,
    add:false,
    del:false

});



for(var i=0;i<filesystem.length;i++)
    jQuery("#list1").jqGrid('addRowData',i+1,filesystem[i]);

jQuery("#list1").setGridParam({rowNum:10}).trigger("reloadGrid");

Works great Thanks @ Thomas and @doctrey

0
3

, XML DOM , HTML DOM, jQuery. , XML, - <file> - , , - :

$(xml).('file').children().each(function() {
    var fileElem = this; // save the instance for closure
    $('ul#theList').append($('<li>').text(fileElem.attr('mount'));
});

XML AJAX, API AJAX jQuery:

$.ajax({
    type: "GET",
    url: "your.xml",
    dataType: "xml",
    success: function(xml) {
        // Insert the previous code snippet here
    }
});

, . . Google "jquery xml"...

+1
0

You probably want to use XSLT - it will allow you to accept the XML response and directly apply the XSL transformation that can be inserted into the DOM.

0
source

All Articles