PHP and Simplecml_load_string and Xpath to echo specific Value
PHP and Simplecml_load_string and Xpath to echo specific Value
我有以下 SOAP 响应:
<?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>
我正在尝试回显/存储上述响应中的 EmailAddress
,以便稍后在脚本中使用它。
我做的是这样的:
$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;
但是我一直收到这个错误:
Fatal error: Call to a member function children() on a non-object in
我真的很想抓住 EmailAddress
。我该怎么做?
尝试找出是否正在创建对象
// Loads the XML
$xml = simplexml_load_string($xmlstring);
if (false === $xml) {
throw new RuntimeException("Error: Cannot create object");
}
如果没有创建对象。然后你可能需要检查你得到的XML。
xml路径错误,忘记了RetrieceResponseMsg。
正确的路径是:
$xml->children("http://schemas.xmlsoap.org/soap/envelope/")->Body->children("http://exacttarget.com/wsdl/partnerAPI")->RetrieveResponseMsg->Results->EmailAddress
我有以下 SOAP 响应:
<?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>
我正在尝试回显/存储上述响应中的 EmailAddress
,以便稍后在脚本中使用它。
我做的是这样的:
$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;
但是我一直收到这个错误:
Fatal error: Call to a member function children() on a non-object in
我真的很想抓住 EmailAddress
。我该怎么做?
尝试找出是否正在创建对象
// Loads the XML
$xml = simplexml_load_string($xmlstring);
if (false === $xml) {
throw new RuntimeException("Error: Cannot create object");
}
如果没有创建对象。然后你可能需要检查你得到的XML。
xml路径错误,忘记了RetrieceResponseMsg。
正确的路径是:
$xml->children("http://schemas.xmlsoap.org/soap/envelope/")->Body->children("http://exacttarget.com/wsdl/partnerAPI")->RetrieveResponseMsg->Results->EmailAddress