我使用的是一些第三方的API,其通过XML返回以下形式的错误:
<xml>
<status>0</status>
<error code="111">Error message text goes here.</error>
</xml>
在PHP中使用simplexml_load_string
我可以很容易地得到状态0和错误消息文本,但我找不到从<error code="111">
检索code="111"
值的方法。它似乎被SimpleXML丢弃。
<?php
$bytesRead = file_get_contents('http://api.....');
$xml = simplexml_load_string($bytesRead);
echo '<pre>'; print_r($xml); echo '</pre>';
?>
输出
SimpleXMLElement Object
(
[status] => 0
[error] => Error message text goes here.
)
我缺少的东西?有没有办法获得这个价值,或有人建议另一种方法来获得这个?
这么简单,谢谢! –
拯救了生命! .............. –
['@attributes]'使用'$ obj-> attributes() - > status' –