An EPP (http://en.wikipedia.org/wiki/Extensible_Provisioning_Protocol), with Namespace support, to a simple Array. Still usable for normal XML too. CDATA is supported.
For regular XML you can use this (probably) fine:
$xml = simplexml_load_string($xmlstring);
$json = json_encode($xml);
$array = json_decode($json,TRUE);
But it doesn't work "out of the box" with namespaces. Also, simplexml_load_string somehow removes certain attributes. For example, if your EPP had:
<domain:contact type="billing">P-ABC120</domain:contact>
It will remove the "type" attribute. And for EPP any missing information makes those methods unusable.
First, load the XML:
PN\Xml2Array::loadXML($xml_string);
//or
PN\Xml2Array::loadXML(file_get_contents('somefile.xml'));
Get the whole array from your complete EPP string:
print_r( PN\Xml2Array::getArray() );
Get all the Namespace prefixes + URI's as an array:
print_r( PN\Xml2Array::getNamespaces() );
Get a part of the EPP in array by giving the prefix:
print_r( PN\Xml2Array::getArrayNS('contact') );
Too lazy to look where in the array/xml a tag is? Or the tag could be changing in different xml files? See example1.php, use it like this:
print_r( PN\Xml2Array::getArrayElement('domain', 'pw', true ) );
Want to get an attribute like:
<result code="1000">...
See example1.php, use it like this:
print_r( Xml2Array::getArrayAttribute(null, 'result', 'code', true) );
Simple as that.
MIT