Jump to Navigation

008 - SimpleXML

PHP offers several different ways of parsing XML, but as of PHP5, the most popular way is to use the SimpleXML extention. SimpleXML works by reading in the entire XML file at once and converting it into PHP object containing all the elements of that XML file chained together in the same way. Once the file has been loaded, you can simply pull data out by traversing the object tree.


$employees = simplexml_load_file('employees.xml');

foreach ($employees->employee as $employee) {

print "{$employee->name} is {$employee->title} at age {$employee->age}\n";



Main menu 2

Story | by Dr. Radut