PDA

Volledige versie bekijken : benadering xml


psychogene
%Europe/Berlin %539 %2005, 13:56
Dit is mijn xml bestand.

<?xml version="1.0" encoding="UTF-8"?>
<slideshow>
<album album_naam="album1" thumb_url="pics\Groove_City_'04\thumb_Groove_City_'04\thumb_I MG_0020.JPG">
<foto thumb_url="pics\Groove_City_'04\thumb_Groove_City_'04\thumb_I MG_0020.JPG" url="pics\Groove_City_'04\IMG_0020.JPG" opmerking="test" />
<foto thumb_url="pics\Groove_City_'04\thumb_Groove_City_'04\thumb_I MG_0021.JPG" url="pics\Groove_City_'04\IMG_0021.JPG" opmerking="test" />
<foto thumb_url="pics\Groove_City_'04\thumb_Groove_City_'04\thumb_I MG_0022.JPG" url="pics\Groove_City_'04\IMG_0022.JPG" opmerking="test" />
</album>
<album album_naam="album2" thumb_url="pics\Groove_City_'04\thumb_Groove_City_'04\thumb_I MG_0011.JPG">
<foto thumb_url="pics\Groove_City_'04\thumb_Groove_City_'04\thumb_I MG_0011.JPG" url="pics\Groove_City_'04\IMG_0011.JPG" opmerking="test" />
<foto thumb_url="pics\Groove_City_'04\thumb_Groove_City_'04\thumb_I MG_0012.JPG" url="pics\Groove_City_'04\IMG_0012.JPG" opmerking="test" />
<foto thumb_url="pics\Groove_City_'04\thumb_Groove_City_'04\thumb_I MG_0013.JPG" url="pics\Groove_City_'04\IMG_0013.JPG" opmerking="test" />
</album>
</slideshow>


Het aanroepen van het xml bestand werkt, maar heb een vraag hoe ik de verschillende albums kan aanspreken.

hiermee:

var fotos:Array = this.firstChild.firstChild.childNodes;


krijg ik al de fotos van het eerste album, maar om het 2de album te krijgen hoe gaat dat in zijn werk?
Ik weet dat het gaat met .nextSlibling, maar als je dan bv 100 albums hebt moet je dan 100 keer .nextSlibling gebruiken.
Of is hier een betere methode voor.

Hoop dat mijn vraag wat duidelijk is.

Grts

Dauntless
%Europe/Berlin %542 %2005, 14:00
var fotos:Array = this.firstChild.childNodes[0]childNodes;

Voor het tweede album :)

Jobu
%Europe/Berlin %547 %2005, 14:08
Eigenlijk roep je het beste eerst de album-nodes aan, en uit elke album-node lees je de foto's in.
In mijn onderstaand voorbeeld maak ik van elke album een button aan, en bij een onPress maakt mijn functie CreateFotos de juiste foto_thumbs aan:

var albums:Array = this.firstChild.childNodes;
var spacing:Number = 19;
for (var i:Number=0; i<albums.length;i++){
current_album = albums[i];
alb_mc = attachMovie("album_btn","album_"+i,i);
alb_mc._x = 10;
alb_mc._y = 100 + (spacing * i);
alb_mc.album_txt.text = current_album.attributes.album_name;

alb_mc.photos = current_album.childNodes //foto's ophalen
alb_mc.onPress = function(){
CreateFotos(this.photos);
}
}
Jobu

psychogene
%Europe/Berlin %559 %2005, 14:25
merci voor de hulp.

kan nu weer verder.