I have created a loop in JavaScript that reads out the name of my nodes and the value inside.
The loop works for the first node and the second one, but on the rest of the nodes it's just repeating the value of the second node.
So the output gets like this:
Name on nod 1 is title The value in the node is XML Content and Data Name on nod 2 is Author The value in the node is XML Content and Data
Et cetera.
Should I create a loop inside the loop? Ir can I multiloop the entire tree?
if (xmlDoc.parseError != 0) {
alert("Error Code: " + xmlDoc.parseError.errorCode + "\n"
+ "Error Reason: " + xmlDoc.parseError.reason + "\n"
+ "Error Line: " + xmlDoc.parseError.line)
}
root = xmlDoc.documentElement
rootList = root.childNodes
len = rootList.length
x = xmlDoc.getElementsByTagName("title")[0]
y = x.childNodes[0];
for (i = 0; i < len; i++) {
j = i + 1
document.write("Name on nod " + j + " is " + rootList.item(i).nodeName + "<br />")
document.write(" value of the the nod is " + y.nodeValue + "<br />" + "<br />");
}