PHP SimpleXML获取数据

凯蒂·哈德森(Katie Hudson)

我有以下格式的回复

<?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="[email protected]"/>
        </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;

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

谢谢

乔尔莫斯

email是“收件人”节点的属性。

您可以尝试以下方法:

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

http://php.net/simplexmlelement.attributes

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章