Loop through parentNodes?

wxdqz

New Member
I have an xml document that has multiple nodes, for example:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Root>
<Abundance>
<BelknapCounty>xo</BelknapCounty>
<CarrollCounty>xo</CarrollCounty>
<CheshireCounty>o</CheshireCounty>
<CoosCounty>xo</CoosCounty>
</Abundance>
<Abundance>
<BelknapCounty>o</BelknapCounty>
<CarrollCounty>xo</CarrollCounty>
<CheshireCounty>o</CheshireCounty>
<CoosCounty>o</CoosCounty>
</Abundance>
<Abundance>
<BelknapCounty>x</BelknapCounty>
<CarrollCounty>o</CarrollCounty>
<CheshireCounty>x</CheshireCounty>
<CoosCounty>xo</CoosCounty>
</Abundance>
</Root>

And I want to loop through the abundance nodes and childNodes. However, I've only been able to grab the first parentNodes childNodes.

How would I loop through it?


This is my current javascript:

<script type="text/javascript">
function whatSpecies(sel) {
var species = new Array("River Jewelwing"...................etc......);
var county = new Array("BelknapCounty", .........blah blah blah);
var element1 = new Array();
var data1 = new Array();
// grab needed svg elements and change the fill color
var htmlObj, SVGDoc, exists;
htmlObj = document.getElementById('htmlObj');
SVGDoc = htmlObj.getSVGDocument();
var xmlDoc1=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc1.async="false";
xmlDoc1.load("distribution.xml");
var nodes=xmlDoc1.documentElement;


for (x=0; x < species.length; x++){
if (species[x] == sel.options[sel.selectedIndex].value){
exists = x;
}

}





for (r = nodes.firstChild, a=0; a < species.length; r = r.nextSibling, a++){

if(exists == a){
for (y = nodes.firstChild.firstChild, j=0; j < 142 ; y = y.nextSibling, j++){
data1[j] = y.text;
element1[j]= (SVGDoc.getElementById(county[j]));
if (element1[j] != null){
if(data1[j] == "x") {
element1[j].style.setProperty('fill', '#339933');
}
}
}
}


}

}
</script>
 
Back
Top