pn/epp-xml2array
Composer 安装命令:
composer require pn/epp-xml2array
包简介
XML/EPP to a simple readable array, including Namespace and CDATA support
README 文档
README
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.
Why not use xyz?
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.
How to use
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') );
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:
print_r( PN\Xml2Array::getArrayElement('domain', 'pw', true ) );
Added in v1.3
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.
License
MIT
统计信息
- 总下载量: 7.05k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 10
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-11-14