Skip to content
/ xml Public

SimpleXmlElement object-oriented wrapper

Notifications You must be signed in to change notification settings

zoibana/xml

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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

About

SimpleXmlElement object-oriented wrapper

Resources

Stars

Watchers

Forks

Releases

No releases published

Languages