2017-05-31 146 views
-1

正在试图访问简单的XML不能以XML访问属性

SimpleXMLElement Object 
(
    [@attributes] => Array 
     (
      [Index] => 21 
     ) 

    [Data] => Hello world 
) 

我想访问索引属性的属性。我试着下面的代码,但它不是 工作对我来说

$xml->attributes()->Index 
+0

向其添加'echo' – Ghost

+1

尝试'echo $ xml-> attributes ['Index'];'' – Edwin

回答

0

你去那里我的朋友:

$xml->attributes()['Index'] 

有时候,我发现我不得不把结果当它是一个字符串。例如:

(string)$xml->attributes()['Index']