2017 © Pedro Peláez
 

library epp-xml2array

XML/EPP to a simple readable array, including Namespace and CDATA support

image

pn/epp-xml2array

XML/EPP to a simple readable array, including Namespace and CDATA support

  • Saturday, November 14, 2015
  • by PeterNotenboom
  • Repository
  • 2 Watchers
  • 7 Stars
  • 5,377 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 1 Versions
  • 4 % Grown

The README.md

EppXml-2-Array v1.4

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., (*1)

Why not use xyz?

For regular XML you can use this (probably) fine:, (*2)

$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:, (*3)

<domain:contact type="billing">P-ABC120</domain:contact>

It will remove the "type" attribute. And for EPP any missing information makes those methods unusable., (*4)

How to use

First, load the XML:, (*5)

PN\Xml2Array::loadXML($xml_string);
//or
PN\Xml2Array::loadXML(file_get_contents('somefile.xml'));

Get the whole array from your complete EPP string:, (*6)

print_r( PN\Xml2Array::getArray() );

Get all the Namespace prefixes + URI's as an array:, (*7)

print_r( PN\Xml2Array::getNamespaces() );

Get a part of the EPP in array by giving the prefix:, (*8)

print_r( PN\Xml2Array::getArrayNS('contact') );
Added in v1.1

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:, (*9)

print_r( PN\Xml2Array::getArrayElement('domain', 'pw', true ) );
Added in v1.3

Want to get an attribute like:, (*10)

<result code="1000">...

See example1.php, use it like this:, (*11)

print_r( Xml2Array::getArrayAttribute(null, 'result', 'code', true) );

Simple as that., (*12)

License

MIT, (*13)

The Versions

14/11 2015

dev-master

9999999-dev https://github.com/PeterNotenboom/EppXml-2-Array

XML/EPP to a simple readable array, including Namespace and CDATA support

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

xml array epp