User Contributed Notes 6 notes

The documentation is a bit sparse for SimpleXmlIterator. Here is an example showing the use of its methods. xml2Array and sxiToArray work together to convert an XML document to an associative array structure.

Most of the time we need to convert the XML to array or JSON , but now I have to completed the requirement of converting XML to XPath which make our template easily geting the data from XML data source due to the Xpath mapping .Here is the function:

I think it's worth mentioning that you need to call the rewind() method on the SimpleXMLIterator object immediately after initialization before you can start doing any other operations on the object. An example:

<?php$xml = new SimpleXMLIterator('file.xml', null, true);

// $x here will be set to null because the rewind() method has not been called$x = $xml->current();