1. Declare the variables
private var myXML:XML;
private var XML_URL:String ="https://sites.google.com/site/way2db1/oca/create.xml";
private var myXMLURL:URLRequest;
private var myLoader:URLLoader;
2. In the required function, implement this logic:
myXML = new XML();
myXMLURL = new URLRequest(XML_URL);
myLoader = new URLLoader(myXMLURL);
myLoader.addEventListener(Event.COMPLETE, xmlLoaded);
Note: Mostly done in init().
3. All the stuff which you wanted to do after loading the XML, place the code in xmlLoaded().
4. Parsing XML
Here is my XML
<root>
<base id="1">
<empno></empno>
<ename></ename>
</base>
<base id="2">
<empno></empno>
<ename></ename>
</base>
</root>
a) To find the no of main nodes in an XML, use
myXML.base.length();
b) To find the empno from the XML, use
myXML.base[0].empno;
myXML.base[1].empno;
c) To work on base node 1, use
var xmlList:XMLLIST = myXML.base.(@id="1");
No comments:
Post a Comment