# SimpleXML

**URL:** <https://forum.kirupa.com/t/simplexml/142961>\
**Category:** Uncategorized\
**Created:** [April 1, 2005, 8:28pm UTC](https://forum.kirupa.com/t/simplexml/142961 "2005-04-01T20:28:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shimi](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@Shimi](https://forum.kirupa.com/u/Shimi)\
**Post date:** [April 1, 2005, 8:28pm UTC](https://forum.kirupa.com/t/simplexml/142961/1 "2005-04-01T20:28:46Z")

</div>

SimpleXML is a class which takes XML file and build it into nested array

[Source+Example Download](http://phpisrael.dotgeek.org/simplexml/simplexml.zip)

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]
