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
                    )

            )
     ) 

@attributes要素の値を取得するにはどうすればよいですか?

   [title] => Travel to developing countries

   [reviewDate] => 2/20/2012

これは私のコードです

  <?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

   ?>
4

2 に答える 2

2

attributes() メソッドを使用します。

$attrs = $xml->versionInfo->attributes();
echo $attrs['reviewDate'];
于 2012-10-31T13:19:38.667 に答える
1

以下のコードを試してください:

foreach($xml as $key => $value){
      foreach($value->attributes() as $attributeskey0 => $attributesvalue1){
              echo "________[$attributeskey0] = $attributesvalue1";
      }
}
于 2012-10-31T13:21:48.637 に答える