Skip to content

Latest commit

 

History

History
71 lines (55 loc) · 1.35 KB

README.md

File metadata and controls

71 lines (55 loc) · 1.35 KB

Xml\Element

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');