PHP SimpleXML获取数据

时间:2015-11-02 11:51:52

标签: php simplexml

我的回复采用以下格式

<?xml version='1.0'?>
<SOAP-ENV:Envelope xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:ns='urn:xtk:myQyery' xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'>
<SOAP-ENV:Body>
    <ExecuteQueryResponse xmlns='urn:xtk:myQyery' SOAP-ENV:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>
        <pOutput xsi:type='ns:Element' SOAP-ENV:encodingStyle='http://xml.apache.org/xml-soap/literalxml'>
            <recipient email="myemail@email.com"/>
        </pOutput>
    </ExecuteQueryResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

所以我要做的第一件事就是加载字符串

public function checkResponse($serverResponse) {
    $xml = simplexml_load_string($serverResponse);

    if($xml->children('SOAP-ENV', true)->Body->Fault) {
        return false;
    }
    else {
        return true;
    }
}

我做的第一件事就是寻找一个错误,如果有错误,则返回false。如果一切正常,我需要从xml返回电子邮件地址。我试过以下没有成功

return $xml->children('SOAP-ENV', true)->Body->ExecuteQueryResponse->pOutput->recipient;

我如何获取电子邮件地址?

由于

1 个答案:

答案 0 :(得分:1)

电子邮件是“收件人”节点的一个属性。

你可以试试这个:

<audio controls autoplay>

    <source src="http://www.boxca.com/lctj4xdqkhjr/Evgeny_Grinko_-_Вальс_.mp3.html" type="audio/mpeg">

    <source src="http://pressplayaudio.com/?artist=Evgeny-Grinko&track=Field.ogg" type="audio/ogg">

    Your browser does not support the audio element.

</audio>

http://php.net/simplexmlelement.attributes