0
     SimpleXMLElement Object
 (
        [@attributes] => Array
            (
                [projectTypeID] => 10
                [genContentID] => 000001
                [language] => en
                [title] => Travel to developing countries
                [subContent] => default
            )

        [versionInfo] => SimpleXMLElement Object
            (
                [@attributes] => Array
                    (
                        [reviewDate] => 2/20/2012
                        [reviewedBy] => Harvey Simon
                    )

            )
     ) 

How can I get the value of @attributes element?

   [title] => Travel to developing countries

   [reviewDate] => 2/20/2012

this is my code

  <?php   $xml = simplexml_load_file('000001.xml','SimpleXMLElement', LIBXML_NOCDATA);


          echo "<pre>";
           print_r($xml);
          echo "</pre>";

             echo $xml->{'@attributes'}['title'];  // not working
        echo "<br/>";
       echo $xml->versionInfo->{'@attributes'}['reviewDate'];   // not working

   ?>
Shoe
  • 74,840
  • 36
  • 166
  • 272
thecodedeveloper.com
  • 3,220
  • 5
  • 36
  • 67

2 Answers2

3

Use the attributes() method:

$attrs = $xml->versionInfo->attributes();
echo $attrs['reviewDate'];
Alin Roman
  • 287
  • 2
  • 15
1

Try below code:

foreach($xml as $key => $value){
      foreach($value->attributes() as $attributeskey0 => $attributesvalue1){
              echo "________[$attributeskey0] = $attributesvalue1";
      }
}
harsh4u
  • 2,550
  • 4
  • 24
  • 39