stepandalecky / xml-element
一个更好的XML元素,易于迭代,并保持XML结构受控。
v0.2.2
2018-11-03 20:46 UTC
Requires
- php: >=7.0
- ext-simplexml: *
Requires (Dev)
- phpunit/phpunit: ^6.5
This package is not auto-updated.
Last update: 2024-09-16 05:18:12 UTC
README
更方便地读取XML。
StepanDalecky/xml-element 是
- 易于使用,
- 易于迭代,
- 保持XML结构受控,
- 可预测。
安装
使用 composer
composer require stepandalecky/xml-element
用法
<grandpa name="Splinter" species="rat">
<father name="Donatello">
<sohn>me</sohn>
</father>
<uncle name="Michelangelo"></uncle>
<uncle name="Leonardo"></uncle>
</grandpa>
use StepanDalecky\XmlElement\Element;
$grandpa = Element::fromString($xmlString);
$grandpa->getAttributes(); // returns ['name' => 'Splinter', 'species' => 'rat']
$grandpa->getAttribute('name'); // returns 'Splinter'
$grandpa->getChild('father')
->getChild('sohn')
->getValue(); // returns 'me'
$grandpa->getChild('mother'); // throws an exception - not found
$grandpa->hasChild('mother'); // returns false
$grandpa->getChild('uncle'); // throws an exception - more children found
$grandpa->hasChild('uncle'); // returns true
$grandpa->getChildren('uncle'); // returns an array consisting of two elements