The SimpleXML library in PHP converts XML into objects that can be accessed like an array. There is both an object oriented and a procedural way of doing it:
With both the procedural and object oriented approaches a SimpleXMLElement object is returned. What SimpleXMLElement provides is a way to access the XML document as you would an array. For example, given the following XML document:
SEC
Florida
East
Georgia
East
Kentucky
East
South Carolina
East
Tennessee
East
Vanderbilt
East
Below is another way of producing the same output. Note the use of the children() and attributes() functions. Unlike the previous example, specific knowledge of the tag and attribute names was not needed:
1234567891011121314151617181920
<?php$xml_object=newSimpleXMLElement('sec_football.xml',NULL,true);list_all($xml_object);functionlist_all($xml_object){if($xml_object!=NULL){$attr=$xml_object->attributes();if($attr[0]!=NULL){echo$attr[0]."\n\n";}echotrim($xml_object);foreach($xml_object->children()as$child){# to get the tag name itself you would# use the $child->getName() functionlist_all($child);}echo"\n";}}?>