我有一个具有以下节点的 SimpleXML 对象,@attributes
. 这是simplexml_load_string()
从 USPS 获得的 XML 字符串的结果。
$xml =
SimpleXMLElement Object
(
[@attributes] => Array
(
[CLASSID] => 3
)
[MailService] => Priority Mail Express 1-Day
[Rate] => 19.10
)
我意识到您可以执行以下操作
$temp = $xml->attributes(); // will return object with '@attributes' note
$temp = (array)$temp; // now in array form
echo $temp['@attributes']['CLASSID']; // prints 3
$xml->{'Rate'}; // will return the rate (19.10) as a string
有什么特别的原因,为什么你想要@attributes
这个CLASSID
?为什么不直接做CLASSID
一样MailService
or Rate
?