这是我第一次尝试使用SimpleXML ...通常我用regexp解析xml文件,但是时间去学习一些新内容......
我得到的XML包含:
<resData>
<something:infData xmlns:something="<censored>" xsi:schemaLocation="<censored>">
<something:name>hello this is my name</something:name>
<something:key>
<something:token>fdba8ee15e4473e12ac342ae15acef2</something:token>
</something:key>
</something:infData>
</resData>
我通过simplexml_load_string()
函数解析xml ...
我可以通过$ xml-&gt; resData将resData作为SimpleXMLObject获取...但是如何获得something:name
和something:key -> something:token
?我无法使用$xml->resData->something:name
,因为它会抛出错误。
答案 0 :(得分:0)
我的问题的答案是:
$xml->response->resData->children('something',true)->children('something',true)->name
$xml->response->resData->children('something',true)->children('something',true)->key->children('something',true)->token