selecting a childNode by attribute and looping through all of it's childNodes to create an array
Translate:
Question: Hello All,
Please help, I'm trying to select a childNode by attribute and looping through all of it's childNodes to create an array.
This is the stripped down skeleton of the XML.
So I want to build an array from the childNodes of the page with the id="extLinks"
This cannot be an absolute reference since many <page> nodes may be added and the node could be anywhere within the XML doc.
==========================
xml
==========================
<?xml version="1.0" encoding="utf-8"?>
<site>
<tracking embed/>
<country codes/>
<pages>
<page id="page1">
</page>
<page id="page2" >
</page>
<page id="extlinks">
<link sLink="
http://www.msn.com"
/>
<link sLink="
http://www.google.com"/>
<link sLink="
http://www.yahoo.com"/>
</page>
</pages>
</site>
==========================
=====
broken AS
This is where I am at and it is becoming a jumble.
==========================
=====
extLinkList.onLoad = function(success) {
//trace(extLinkList);
var linkArray:Array = new Array();
for (m=0; m<3; m++) {
var sLink:String;
var xmlNodeBase:XMLNode = extLinkList.childNodes[0].
childNodes
[2].childN
odes;
var xmlNodeBasePlus = xmlNodeBase.childNodes[m];
if (xmlNodeBase.attributes.id
== "extLinks") {
xmlNodeBasePlus=xmlNodeBas
e.childNod
es[m]
sLink = xmlNodeBasePlus.attributes
.sLink;
linkArray.push(sLink);
}
}
extLink1 = linkArray[0];
extLink2 = linkArray[1];
extLink3 = linkArray[2];
trace(linkArray);
};
==========================
======
This returns nothing, I am assuming that it is not finding anything because the if loop is never entered.
Thanks for all your input.