How to create a Javascript array from xml file attributes in jQuery
<p>I am using <a href="http://trirand.com/blog/jqgrid/jqgrid.html" rel="nofollow">jqGrid</a>, but it cannot take attributes from a xml file. So I wanted to have a array out the xml something like below. Please help me create an array from the xml file below</p>

<p>jqGrid supported array format</p>

<pre><code>var mydata = [
    {id:"1",invdate:"2007-10-01",name:"test",note:"note",amount:"200.00",tax:"10.00",total:"210.00"},
    {id:"2",invdate:"2007-10-02",name:"test2",note:"note2",amount:"300.00",tax:"20.00",total:"320.00"},
    {id:"3",invdate:"2007-09-01",name:"test3",note:"note3",amount:"400.00",tax:"30.00",total:"430.00"},
    {id:"4",invdate:"2007-10-04",name:"test",note:"note",amount:"200.00",tax:"10.00",total:"210.00"},
    {id:"5",invdate:"2007-10-05",name:"test2",note:"note2",amount:"300.00",tax:"20.00",total:"320.00"},
    {id:"6",invdate:"2007-09-06",name:"test3",note:"note3",amount:"400.00",tax:"30.00",total:"430.00"},
    {id:"7",invdate:"2007-10-04",name:"test",note:"note",amount:"200.00",tax:"10.00",total:"210.00"},
    {id:"8",invdate:"2007-10-03",name:"test2",note:"note2",amount:"300.00",tax:"20.00",total:"320.00"},
    {id:"9",invdate:"2007-09-01",name:"test3",note:"note3",amount:"400.00",tax:"30.00",total:"430.00"}
    ];
</code></pre>

<p>My xml</p>

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

<p>How to create a JS array in jquery or JS, out of the above xml for the attributes under <code>csmclient&gt;system&gt;filesystem&gt;file</code> eg: <code>mount</code>, <code>free</code>, <code>total</code>, <code>used</code> and <code>percentage</code> attributes</p>

<p><strong>Updated</strong></p>

<pre><code>var filesystem=[];
$(xml).find('file').each(function(){ 
    console.info($(this).attr('total')+", "+$(this).attr('free')+", "+$(this).attr('used')+", "+$(this).attr('percentage'));
    var row={};
    row.total=$(this).attr('total');
    row.free=$(this).attr('free');
    row.used=$(this).attr('used');
    row.percentage=$(this).attr('percentage');
    filesystem.push(row);
});
</code></pre>
