hey all, I’m trying to access some information in XML. I got the first few nodes working, but for the life of me, I can’t figure out how to get to the nested nodes. I’ve tried everything i can think of. I thought it would have to do with nested for loops, but i couldn’t get it to work. What am I missing? I’ve been pretty successful with simple XML, and this is relatively simple too, but more than I’m used to at this point… If there is a better way to do any of this, I’m all ears (or all eyes in this case :))
var categories:Array = new Array();
var titles:Array = new Array();
var subTitles:Array = new Array();
var noms:Array = new Array();
var copies:Array = new Array();
var covers:Array = new Array();
var medias:Array = new Array();
var nominees:XML = new XML();
nominees.ignoreWhite = true;
nominees.onLoad = function(success:Boolean) {
if (success) {
var xnRoot:XMLNode = this.firstChild;
var xnCategory:XMLNode;
var xnTitle:XMLNode;
var xnSubTitle:XMLNode;
var xnNom:XMLNode;
var xnCopy:XMLNode;
var xnCover:XMLNode;
var xnMedia:XMLNode;
for (i=0; i<xnRoot.childNodes.length; i++) {
var xnCategory:XMLNode = xnRoot.childNodes*;
var xnTitle:XMLNode = xnCategory.childNodes[0];
titles.push(xnCategory.childNodes[0]);
subTitles.push(xnCategory.childNodes[1]);
noms.push(xnCategory.childNodes[2]);
for (j=0; j<xnCategory.childNodes[2].childNodes.length; j++) {
var xnNoms:XMLNode = xnCategory.childNodes[2];
copies.push(xnNoms.childNodes[0]);
covers.push(xnNoms.childNodes[1]);
medias.push(xnNoms.childNodes[2]);
trace(noms);
}
}
}
};
//
nominees.load("nominees2.xml");
<?xml version="1.0" encoding="ISO-8859-1"?>
<nominees>
<category>
<title>Single of the Year</title>
<subTitle>(Award goes to artist and producer)</subTitle>
<nom>
<nomCopy>This is the copy.</nomCopy>
<cover>cover_bAndD_hillbillyDeluxe.jpg</cover>
<media>single_nom1.mp3</media>
</nom>
<nom>
<nomCopy>This is the copy2.</nomCopy>
<cover>cover_ku_beHere.jpg</cover>
<media>single_nom2.mp3</media>
</nom>
<nom>
<nomCopy>This is the copy3.</nomCopy>
<cover>cover_cu_someHearts.jpg</cover>
<media>single_nom3.mp3</media>
</nom>
<nom>
<nomCopy>This is the copy4.</nomCopy>
<cover>cover_kc_theRoadAndTheRadio.jpg</cover>
<media>single_nom4.mp3</media>
</nom>
<nom>
<nomCopy>This is the copy5.</nomCopy>
<cover>cover_bp_timeWellWasted.jpg</cover>
<media>single_nom5.mp3</media>
</nom>
</category>
<category>
<title>Song of the Year</title>
<subTitle>(Award goes to artist and producer)</subTitle>
<nom>
<nomCopy>This is the song copy.</nomCopy>
<cover>cover_1.jpg</cover>
<media>song_nom1.mp3</media>
</nom>
<nom>
<nomCopy>This is the song copy2.</nomCopy>
<cover>cover_2.jpg</cover>
<media>song_nom2.mp3</media>
</nom>
<nom>
<nomCopy>This is the song copy3.</nomCopy>
<cover>cover_3.jpg</cover>
<media>song_nom3.mp3</media>
</nom>
<nom>
<nomCopy>This is the song copy4.</nomCopy>
<cover>cover_4.jpg</cover>
<media>song_nom4.mp3</media>
</nom>
<nom>
<nomCopy>This is the song copy5.</nomCopy>
<cover>cover_5.jpg</cover>
<media>song_nom5.mp3</media>
</nom>
</category>
<category>
<title>Video of the Year</title>
<subTitle>(Award goes to artist and producer)</subTitle>
<nom>
<nomCopy>This is the video copy.</nomCopy>
<cover>cover_1.jpg</cover>
<media>video_nom1.flv</media>
</nom>
<nom>
<nomCopy>This is the video copy2.</nomCopy>
<cover>cover_2.jpg</cover>
<media>video_nom2.flv</media>
</nom>
<nom>
<nomCopy>This is the video copy3.</nomCopy>
<cover>cover_3.jpg</cover>
<media>video_nom3.flv</media>
</nom>
<nom>
<nomCopy>This is the video copy4.</nomCopy>
<cover>cover_4.jpg</cover>
<media>video_nom4.flv</media>
</nom>
<nom>
<nomCopy>This is the video copy5.</nomCopy>
<cover>cover_5.jpg</cover>
<media>video_nom5.flv</media>
</nom>
</category>
</nominees>
Basically, I’m having trouble getting to the “nomCopy”, “cover” and “media” info…