php - 使用 PHP 从 SOAP 响应中获取价值
问题描述
我正在尝试从下面的肥皂响应中获取“ErrorDetail”,但对我不起作用。我的反应很好。我试过这个。
$response = curl_exec($ch);
$response_xml = str_replace("<SOAP-ENV:Body>","", $response);
$response_xml = str_replace("</SOAP-ENV:Body>","", $response_xml);
$return = simplexml_load_string($response_xml);
$value = (string) $return->lodgeWithCertificateResponseType->Notification->Id;
$status = (string) $return->lodgeWithCertificateResponseType->Notification->Status;
$error = (string) $return->detail->fault->ErrorMessage;
肥皂反应是
string(617) "<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/><SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Server</faultcode>
<faultstring xml:lang="en">Validation error</faultstring>
<detail>
<fault xmlns:ns3="http://bdm.nsw.gov.au/Schemas/CommonTypes_v1.0" xmlns:ns4="http://bdm.nsw.gov.au/Schemas/StatusQuery_v1.0">
<ErrorMessage>Validation error</ErrorMessage>
<ErrorDetail>Deceased's family name at birth must be in capitals</ErrorDetail>
<ErrorDetail>Deceased's Family Name must be in capitals</ErrorDetail>
</fault>
</detail>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>"
object(SimpleXMLElement)#1 (0) {
}
任何帮助将不胜感激
解决方案
尝试这样的事情:
$string = <<<XML
[your SOAP response above]
XML;
$xml = simplexml_load_string($string);
$results = $xml->xpath('//fault/ErrorDetail');
$err = $results[0]->xpath('./preceding-sibling::ErrorMessage/text()');
echo $err[0]."\r\n";
foreach($results as $result) {
echo $result;
echo "\r\n";
}
输出:
Validation error
Deceased's family name at birth must be in capitals
Deceased's Family Name must be in capitals
推荐阅读
- c++ - 分配一个仅作为抽象类指针的对象
- docker - 如何从给定的 docker 网络内部连接到 L2TP/Ipsec 后面的主机?
- python - Pandas:如何为数据框中的每个重复行创建一个计数器
- flutter - 空安全迁移后如何解决库/包之间的冲突?
- c# - 嵌套类中的依赖注入
- spring-boot - 在 mvn 依赖项后运行 mvn -o clean package 时缺少依赖项:在创建 docker 映像时脱机
- sql-server - 通过作业执行时的SSIS包成功执行但不发送电子邮件
- javascript - 在 HTML 画布中在线矢量的左侧或右侧绘制不同宽度的线条
- android - android 应用程序通过电子邮件发送图像失败,找不到文件或权限
- javascript - 双栈导航标题