Click to See Complete Forum and Search --> : xml data mine / loop in loop


DMouse
04-21-2003, 10:08 PM
I am trying to mine an xml doc with javascript, looping through the parent nodes and then looping through the children within those nodes to output the values. I am getting the child values for the first parent but then it exits the first loop so I only get one recordset. Playing around with the curly braces allows me to get the last record but not the first. The short story is that I'm getting only one record. Any help will be welcome.

function display(recordSet)
{
var output
var menu = recordSet.documentElement.nodeName;
var length = recordSet.childNodes(1).childNodes.length; // obtains recordset count
output = "<h1><center>" + menu + length + "</center></h1><br><br>"

for(i=0;i<length;i++){
var node = recordSet.documentElement.childNodes(i)
var nodeLength = node.childNodes.length// number of product attributes
output += "<h3>" + node.nodeName + "</h3><br><br>"

for(i=0;i<nodeLength;i++){ // loop the product attributes
var attributeName = node.childNodes(i).nodeName // attribute name
var attributeValue = node.childNodes(i).firstChild.nodeValue // attribute value
if (attributeName=="pic")
output +="<img src='" + attributeValue + "'><br><br>"
else
output += attributeValue + "<br><br>"

}

}
return output

}

khalidali63
04-21-2003, 10:11 PM
you should have posted this in XML area.....anyways,
for your answer,to go through the elements in an xml document think in recursive loops,

create a function that will call itself if a child has more elements..until it gets to the last who does not have any children of type==1

hope this guides you...