我知道这个问题的答案非常简单,但这是我似乎无法使用 google/SO 解决的问题之一,因为它处理的字符很难搜索。我正在使用 php 从 rest api 获取 xml。我使用了 simple_xml_load_string($string) 现在当我 print_r 我得到这个:
SimpleXMLElement Object
(
[Seaports] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[Id] => 8675309
[Name] => CHORIZON WIRELUSS
)
[Statistics] => SimpleXMLElement Object
(
[Clicks] => 194
)
ETC
假设我想要
$xml->Seaports[0]->@attributes['Id']
echo $xml->Seaports[0]->@attributes['Id'];
给我一个语法错误和
echo $xml->Seaports[0]->attributes['Id'];
我究竟做错了什么?