zoibana / xmlparser
Simplexml wrapper
Installs: 9
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
pkg:composer/zoibana/xmlparser
Requires
- php: >=7
- ext-libxml: *
- ext-simplexml: ^7.4
This package is auto-updated.
Last update: 2025-12-10 17:56:49 UTC
README
zoibana\Xml\Element class extends the SimpleXmlElement class and adds few new methods
Initialization
$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>
");
Added methods
first()
retrieves the first element of requested tag elements list
$firstOfferPrice = (int) $xml->offer->first()->price;
last()
retrievs the last element of requested tag elements list
$lastOfferPrice = (int) $xml->offer->last()->price;
index($index)
retrieves element with index $index of requested tag elements list
$thirdOfferPrice = (int) $xml->offer->index(2)->price;
attr($attr)
returns the attribute value
$idAttribute = $xml->offer->attr('id');
column($tagname)`
returns the array of tag values for each element
$arrayOfOfferPrices = $xml->offer->column('price');
attrColumn($tagname)
returns the array of attribute values for each element
$arrayAttributeIds = $xml->offer->attrColumn('id');