Home > Code Dump > Basic XML Handling in PHP

Basic XML Handling in PHP

When I used to think of XML, I always thought of bundles of Regex...
By 20/12/11 [Last Edited by Joseph 20/12/11]
BOOKMARK
LOGIN
REGISTER
When I first needed to process XML files or XML RPC calls in PHP, I found out about the wonders of the SimpleXML class in PHP

$xml_text = file_get_contents('file.xml'); //Get the XML file
$smpxml = new SimpleXMLElement($xml_text);

foreach($smpxml as $key) {
    print_r($key);
}

You can access attributes using the attributes() method

echo $user->attributes()->type; //For example