Creating associative array in a for-loop

HackerS

New Member
I have a big xml document that i'm trying to process into an array in javascript.\[quote\]\[code\]<DR> <C> <SWDGDRC> <CID>0</CID> <V>06/01/2012 00:00:00</V> </SWDGDRC> <SWDGDRC> <CID>1</CID> <V>1131</V> </SWDGDRC> <SWDGDRC> <CID>2</CID> <V>28800</V> </SWDGDRC> </C> <rowid>0</rowid></DR><DR> <C> <SWDGDRC> <CID>0</CID> <V>06/02/2012 00:00:00</V> </SWDGDRC> <SWDGDRC> <CID>1</CID> <V /> </SWDGDRC> <SWDGDRC> <CID>2</CID> <V /> </SWDGDRC> </C> <rowid>1000</rowid>\[/code\]\[/quote\]It consists of multiple DR(datarow) and each DR has multiple C (columns) and a rowid.I'm trying to loop all this data into an associative array:\[code\] for(var i=0; i < DR.length; i++) { // loop DR for(var j=0; j < DR.getElementsByTagName('C').length; j++) { // loop C for(var k=0; k < DR.getElementsByTagName('C')[j].getElementsByTagName('SWDGDRC').length; k++) { //loop SWDGDRC columnData = { "rowid": DR.getElementsByTagName('rowid')[0].textContent, "column": { columnID: DR.getElementsByTagName('C')[j].getElementsByTagName('SWDGDRC')[k].getElementsByTagName('CID')[0].textContent, value:DR.getElementsByTagName('C')[j].getElementsByTagName('SWDGDRC')[k].getElementsByTagName('V')[0].textContent } }; } } }\[/code\]The problem is I want to make an new array in the "column" key which loops all the C (columns) data so I can access this data using something like this: columnData[0]['column'][0]['columnID']
 
Back
Top