SimpleXML is a class which takes XML file and build it into nested array
usage example:
[AS]
// SimpleXMLobj.getData().mainnode[0].subnode[0]._getAttribute(“attributename”));
var xmlObj:SimpleXML = new SimpleXML(xml);
var name1:String = xmlObj.getData().country[0].city[0]._getAttribute(“name”));var name2:String = xmlObj.getData().country[0].city[1]._getAttribute(“name”));
[/AS]
Available function are:
[AS]
_getAttribute(“AttributeName”) //Get an attribute from a node
_getText() //Get the text inside of a node
_getAt(Number) //Get sub node at number
_getFirst() //Get first sub node
_getLast() //Get last sub node
_hasNodes //Return if node have sub nodes
/*And you can use any Array function because it extends from Array!
For example: length
*/
[/AS]
A short example:
[AS]
var xmlObj:SimpleXML = new SimpleXML(xml);
var CountriesNode:Node = xmlObj.getData().countries[0];
var i:Number;
var x:Number;
for (i = 0; i<CountriesNode.country.length; i++) {
trace("////////////////////////////////");
trace(“Country Name: " +CountriesNode.country*._getAttribute(“name”));
trace(“Description:”);
trace(” " + CountriesNode.country*.desc1[0]._getText());
trace(“Cities List:”);
for (x = 0; x<CountriesNode.country*.city.length; x++) {
trace(" City Name: " + CountriesNode.country*.city[x]._getAttribute(“name”));
}
trace("////////////////////////////////
");
}
} catch (e:XMLSourceException) {
trace(e.message);
}
[/AS]