XML get certain node with specific attribute and the next one

albiume

New Member
I need to collect values from an XML-file, the file can look like this:\[code\]<Invoice><Description>Insur 2012-12-22</Description><Description>Insur 2012-12-12</Description><Description>Insur 2011-02-12</Description></Invoice><Invoice><Description>Insur 2012-11-21</Description><Description>Insur 2012-06-01</Description><Description>Insur 2011-02-18</Description><Description>Insur 2011-02-18</Description><Description>Insur 2011-02-18</Description></Invoice>\[/code\]And for every \[code\]<Description>\[/code\] I want to save the value in an array, im trying to use a loop like this:\[code\]y=xmlDoc.documentElement;x=y.getElementsByTagName("Invoice");var descs = new Array();for (i=0;i<x.length;i++) { des=x.getElementsByTagName("Description"); for(var j=0; j<des.length; j++){ var desc = des[j].childNodes[0].nodeValue; if(desc.match("Insur")){ desc = desc.substring(5, 15); desc = desc.replace( /-/g, "" ); descs=desc; } }}\[/code\]If I dont use break in the loop, Ill only get output for the first node, and if I use break Ill get only the first \[code\]<Description>\[/code\] node for every \[code\]<Invoice>\[/code\].So I want to save all the dates in an array, so for the first \[code\]<Invoice>\[/code\] I want to save the three dates in the array. The second I want the five dates in the array, after the first three dates.
 
Back
Top