![](/img/trans.png)
[英]Trouble with simplexml_load_string in PHP with Soap response
[英]How to parse this SOAP XML response with PHP simplexml_load_string?
恐怕我对如何使用名称空间和前缀解析此XML感到困惑。 这是我从Curl请求中获得的SOAP回复:
<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">
<soap:body>
<getproductpricekonfigurationresponse xmlns="https://service.printapi.de/interface/">
<getproductpricekonfigurationresult>
<xs:schema id="ProduktPreisKonfiguration" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"></xs:schema>
<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<produktpreiskonfiguration xmlns>
<produktkonfiguration diffgr:id="ProduktKonfiguration1" msdata:roworder="0" diffgr:haschanges="inserted">
<idobjekt>4</idobjekt>
<idformat>30</idformat>
<ustidentnr>
<objektpreisnetto>18.77</objektpreisnetto>
<mwstwert>6.01</mwstwert>
</ustidentnr>
</produktkonfiguration>
</produktpreiskonfiguration>
</diffgr:diffgram>
</getproductpricekonfigurationresult>
</getproductpricekonfigurationresponse>
</soap:body>
</soap:envelope>
例如,如果要回显“ objektpreisnetto”节点,该怎么办?
编辑:这是我尝试过的一些事情(以及其他):
$xml = simplexml_load_string($soap);
$result = $xml->children('http://schemas.xmlsoap.org/soap/envelope/')
->children('https://service.printapi.de/interface/')
->getproductpricekonfigurationresult
->objektpreisnetto;
echo $result->objektpreisnetto;
那什么也没返回,但是我确定我没有正确处理子部件。
这是我尝试过的一个更基本的示例,该示例也未返回任何内容:
$xml = simplexml_load_string($soap);
foreach ($xml->children('http://schemas.xmlsoap.org/soap/envelope/') as $child)
{
echo "Child node: " . $child . "<br>";
}
那不应该至少返回一个子节点吗? 任何见解将不胜感激!
SoapClient通过在SoapClient选项中设置login
和password
处理HTTP身份验证,您是否尝试过?
然后使用Wsdl到php生成器来帮助您获取将用作类映射的相应PHP类,请尝试https://www.wsdltophp.com 。
因此,您只需要处理PHP对象,就不必解析任何内容。
我设法使这个工作!
首先,我使用curl来登录并发送此请求中概述的SOAP请求: https : //stackoverflow.com/a/7157785/1121877
然后,我按此处概述的方式用simplexml_load_string加载返回的XML: https : //stackoverflow.com/a/8275835/1121877
因此,感谢大家分享他们的知识!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.