Parse and get xml node using php

XML parsing essentially means traversing through the XML and returning the data. Nowadays, A number of web services return data in JSON format, but a large number still use XML.

There are two methods for loading XML,

the simplexml_load_file() will load the XML from a file and the simplexml_load_string() will load the XML from a literal string.

 

$fileData = '<Course><Result><Status status="passed"/></Result></Course>';

$xml = simplexml_load_string($fileData);

$status = (string) $xml->Course->Result->Status['status'];

echo $status; // prints "passed"