zoibana / xmlparser
dev-master
2021-10-10 08:44 UTC
Requires
- php: >=7
- ext-libxml: *
- ext-simplexml: ^7.4
This package is auto-updated.
Last update: 2024-09-10 15:06:37 UTC
README
zoibana\Xml\Element类扩展了SimpleXmlElement类,并添加了一些新方法
初始化
$xml = new zoibana\Xml\Element("
<xml>
<offer internal-id="30192">
<price>123036</price>
</offer>
<offer internal-id="30193">
<price>32412</price>
</offer>
<offer internal-id="30194">
<price>53123</price>
</offer>
<offer internal-id="30195">
<price>9676253</price>
</offer>
<offer internal-id="30196">
<price>13687</price>
</offer>
</xml>
");
添加的方法
first()
检索所需标签元素列表中的第一个元素
$firstOfferPrice = (int) $xml->offer->first()->price;
last()
检索所需标签元素列表中的最后一个元素
$lastOfferPrice = (int) $xml->offer->last()->price;
index($index)
检索所需标签元素列表中索引为$index的元素
$thirdOfferPrice = (int) $xml->offer->index(2)->price;
attr($attr)
返回属性值
$idAttribute = $xml->offer->attr('id');
column($tagname)
返回每个元素的标签值数组
$arrayOfOfferPrices = $xml->offer->column('price');
attrColumn($tagname)
返回每个元素的属性值数组
$arrayAttributeIds = $xml->offer->attrColumn('id');