SimpleXML is a tree-based parser. SimpleXML provides an easy way of getting an element's name, attributes and textual content if you know the XML document's structure or layout. SimpleXML turns an XML document into a data structure you can iterate through like a collection of arrays and objects. Compared to DOM or the Expat parser, SimpleXML takes a fewer lines of code to read text data from an element.
In the last tutorial, I gave an introduction to XML parsers in PHP and let us recollect key information from that. SimpleXML parser,
As of PHP 5, the SimpleXML functions are part of the PHP core. No installation is required to use these functions.
Now, its time to experiment the above SimpleXML functions to parse a XML document. First, we should create XML document. Let us take a simple XML document,
To add a child element to a node in a XML document, we use addChild() of SimpleXMLElement class.