Hi everyone.
I am new to XML so like many here struggeling a bit. I know this must very easy but I cant get it to work, as I dont quite understand the naming conventions of XML yet.
I have this XML file:
Code:
<events>
<event id='3' city='Cape Town' shortdate='22/06/2003' longdate='22 June 2003' description='hhh!' location='hhh' path='/flash/events/cpt/20030522/'>
<eventimage thumbfilename='200361714567thumb_3.jpg' fullfilename='200361714567full_3.jpg'/>
<eventimage thumbfilename='20036171833thumb_2.jpg' fullfilename='20036171833full_2.jpg'/>
<eventimage thumbfilename='200361718569thumb_1.jpg' fullfilename='200361718569full_1.jpg'/>
</event>
<event id='9' city='Midrand' shortdate='06/07/2003' longdate='06 July 2003' description='Fish Eagle Experience' location='Expo Centre' path='/flash/events/jhb/20030706/'>
<eventimage thumbfilename='2003617181153thumb_1.jpg' fullfilename='2003617181153full_1.jpg'/>
<eventimage thumbfilename='2003617181210thumb_2.jpg' fullfilename='2003617181210full_2.jpg'/>
<eventimage thumbfilename='2003617181223thumb_3.jpg' fullfilename='2003617181223full_3.jpg'/>
<eventimage thumbfilename='20036171813333thumb_4.jpg' fullfilename='2003617183333full_4.jpg'/>
</event>
<event id='2' city='Cape Town' shortdate='26/06/2003' longdate='26 June 2003' description='Baxter Ball!' location='Baxter' path='/flash/events/cpt/20030525/'>
<eventimage thumbfilename='200361718520thumb_3.jpg' fullfilename='200361718520full_3.jpg'/>
<eventimage thumbfilename='20036171850thumb_2.jpg' fullfilename='20036171850full_2.jpg'/>
<eventimage thumbfilename='200361718444thumb_1.jpg' fullfilename='200361718444full_1.jpg'/>
</event>
<event id='1' city='Durban' shortdate='25/04/2003' longdate='25 April 2003' description='City Hall goes Green!' location='City Hall' path='/flash/events/kzn/20030525/'>
<eventimage thumbfilename='2003617181250thumb_1.jpg' fullfilename='2003617181250full_1.jpg'/>
<eventimage thumbfilename='200361718139thumb_2.jpg' fullfilename='200361718139full_2.jpg'/>
<eventimage thumbfilename='2003617181324thumb_3.jpg' fullfilename='2003617181324full_3.jpg'/>
</event>
</events>
From reading through the forums I have gotten it so far to load all the event lines, but I get stuck inside the first eventimageblock of the first event line, because my loop does not work.
My ActionScript:
Code:
stop();
// create object and prepare for xml load
events_xml = new XML();
events_xml.ignoreWhite = true;
events_xml.onLoad = function(success) {
if (success) {
convertXML();
nextFrame();
} else {
trace("error reading xml");
}
};
//
// load in xml file
events_xml.load("events.xml");
//
// convert xml to object
function convertXML() {
//
_global.events_array = new Array()
//
mainNode = events_xml.firstChild;
eventNodes = mainNode.childNodes;
// read through nodes
for (i=0; i< eventNodes.length; i++) {
//
if (eventNodes[i].nodeName == "event") {
//
events_array[i] = new Object();
// extract events IDnumber
events_array[i].idnumber = eventNodes[i].attributes["id"]
// extract city
events_array[i].city = eventNodes[i].attributes["city"]
// extract shortdate
events_array[i].date = eventNodes[i].attributes["shortdate"]
// extract longdate
events_array[i].longdate = eventNodes[i].attributes["longdate"]
// extract description
events_array[i].description = eventNodes[i].attributes["description"]
// extract location
events_array[i].location = eventNodes[i].attributes["location"]
// extract path of images' folder
events_array[i].path = eventNodes[i].attributes["path"]
trace (events_array[i].idnumber);
trace (events_array[i].city);
trace (events_array[i].date);
trace (events_array[i].longdate);
trace (events_array[i].description);
trace (events_array[i].location);
trace (events_array[i].path);
trace ("===images===")
//THIS IS THE PART THAT WONT WORK ARGH!
imageNodes = mainNode.firstChild.childNodes;
trace (eventNode[2].childNodes[1]);
for (j=0; j< imageNodes.length; j++){
if (imageNodes[j].nodeName == "eventimage"){
trace (imageNodes[j].attributes["thumbfilename"]);
}
}
}
}
// reverse order of events array so latest events are first
events_array.reverse();
// set initial values for main events menu
submenu_landing_mc.startIndex = 0;
submenu_landing_mc.totalEvents = events_array.length;
}
Please, please help, I know for a lot in here this is as easy as it can get..
Thanks for all your time and effort.