dousong9729 2015-08-11 13:16
浏览 62
已采纳

PHP和Simplecml_load_string和Xpath来回显特定的值

I have the below SOAP response:

<?xml version="1.0" encoding="utf-8"?>

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">

<soap:Header>
<wsa:Action>RetrieveResponse</wsa:Action>
<wsa:MessageID>urn:uuid:4bd57838-61fd-4edf-8c66-XXXXXXXX</wsa:MessageID>
<wsa:RelatesTo>urn:uuid:eaa150ab-fe7f-4b9b-855f-YYYYYYYY</wsa:RelatesTo>
<wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>
<wsse:Security><wsu:Timestamp wsu:Id="Timestamp-bcd6b0b0-9fc0-45a1-9363-AAAAAA"><wsu:Created>2015-08-11T09:06:40Z</wsu:Created><wsu:Expires>2015-08-11T09:11:40Z</wsu:Expires></wsu:Timestamp></wsse:Security>
</soap:Header>

<soap:Body>
<RetrieveResponseMsg xmlns="http://exacttarget.com/wsdl/partnerAPI">
    <OverallStatus>OK</OverallStatus>
    <RequestID>12af20a5-b76e-4043-ae76-XXXXXXXX</RequestID>
    <Results xsi:type="Subscriber">
        <PartnerKey xsi:nil="true" />
        <ObjectID xsi:nil="true" />
        <EmailAddress>hrajput@testing.com</EmailAddress>
        <Status>Active</Status></Results>
    <Results xsi:type="Subscriber">
        <PartnerKey xsi:nil="true" />
        <ObjectID xsi:nil="true" />
<EmailAddress>hrajput@testing.com</EmailAddress>
<Status>Active</Status></Results>
</RetrieveResponseMsg>
</soap:Body></soap:Envelope>

I am trying to echo / store the EmailAddress from the above response so I can use it later on in the script.

What I am doing is this:

$xmlstring = $client->__getLastResponse();

// Loads the XML
$xml = simplexml_load_string($xmlstring);

//print $xml->asXML();

echo "Result:".$xml->children('http://schemas.xmlsoap.org/soap/envelope/')->Body->children('http://exacttarget.com/wsdl/partnerAPI')->Results[0]->EmailAddress;

But I keep getting this error:

Fatal error: Call to a member function children() on a non-object in

I'm really at my wits end trying to grab the EmailAddress. How can I do this?

  • 写回答

2条回答 默认 最新

  • dotxxh0998 2015-08-11 13:42
    关注

    The xml path is wrong, you forgot RetrieceResponseMsg.

    The correct path is:

    $xml->children("http://schemas.xmlsoap.org/soap/envelope/")->Body->children("http://exacttarget.com/wsdl/partnerAPI")->RetrieveResponseMsg->Results->EmailAddress
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP