【发布时间】:2014-03-31 15:38:21
【问题描述】:
恐怕我不知道如何用名称空间和前缀解析这个 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>";
}
不应该至少返回一个子节点吗?任何见解将不胜感激!
【问题讨论】:
-
为什么不使用 SOAP 客户端而不是 simpleXML?您能否展示您尝试过的方法并具体说明哪些方法不起作用?
-
XML 无效:xmlvalidation.com
-
我没有使用 SOAP 客户端,因为我连接的 SOAP 服务使用的是 HTTP 授权,所以我使用 curl。