I have the following code, which will output the child-elements of the “weather” element.
x=xmlDoc.getElementsByTagName("weather")[0].childNodes;
for (i=0;i<x.length;i++) {
var parent = x[i].nodeName;
document.write("<b>"+parent+"</b><br />");
}
This will get the following childs:
forecast_information, current_conditions, forecast_conditions,
forecast_conditions, forecast_conditions and forecast_conditions.
Now I want to retrieve all the childs of those elements. Probably with a loop inside a loop, that’s why I tried the following:
for (i=0;i<x.length;i++) {
var parent = x[i].nodeName;
document.write("<b>"+parent+"</b><br />");
y=xmlDoc.getElementsByTagName(parent)[i].childNodes;
for (h=0;h<y.length;h++) {
var child = y[i].nodeName;
document.write(child+"<br />");
}
}
But this doesn’t work.. It wil get the output:
forecast_information
city (7 times)
current_conditions
Thats all.. Any help?
Thanks in advance!
Don’t do another call to getElementsByTagName. Just use childNodes on each element in your loop to get the children’s children: