带有“:”的PHP SimpleXML对象

时间:2013-11-25 12:49:03

标签: php xml simplexml

这是我第一次尝试使用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:namesomething:key -> something:token?我无法使用$xml->resData->something:name,因为它会抛出错误。

1 个答案:

答案 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