Saturday, September 06, 2008

[XML Parsing] The Loader

1: Loading the XML File

 

I am not going to go into loads of detail about what everything does, for now anyway, just the code and what some of the bits do.  I will however highlight the bits you won't need to change and the bits you will.

 

To load the xml file:

 

(Actionscript 3.0 code)

 

01. var xmlLoader:URLLoader = new URLLoader();
02. var xmlData:XML = new XML();

03.

04. xmlLoader.addEventListener(Event.COMPLETE, LoadXML);

05. xmlLoader.load(new    

     URLRequest("http://83.170.89.79/~gibboco/blog/
     tutorials/xml/myXML.xml"));

06. function LoadXML(e:Event):void
07. {
08.     xmlData = newXML(e.target.data);
09.     trace(xmlData);
10. }

 

01 to 04: Can be left alone, just sets stuff up for you (if you change 'LoadXML' on line 4, you will have to change the function name in 06 as well).

 

05: Loads in your xml file.  This bit you need to change to the location of your xml file or use the one I have uploaded (used in the example).  The kirupa example uses the url http://www.kirupa.com/net/files/sampleXML.xml which displays some info on books, which the kirupa tutorial uses for showing information.

 

06 to 10: The function.  Can be left alone.  This sets 'xmlData' to the value of the content of your XML file and displays it in the output (by tracing xmlData).

 

My XML file: myXML.txt (you'll need to save it as an xml file) (if you want to have it link to an internal file on your computer)

 

 

 

 



No comments: