Php 使用名称空间和属性迭代SOAP响应
我正在尝试解析从DHLWeb服务获得的soap代码。我使用php cUrl生成请求,然后得到响应(包括名称空间和属性):Php 使用名称空间和属性迭代SOAP响应,php,web-services,curl,soap,Php,Web Services,Curl,Soap,我正在尝试解析从DHLWeb服务获得的soap代码。我使用php cUrl生成请求,然后得到响应(包括名称空间和属性): 为什么不使用SoapClient呢?否则,响应可以由SimpleXML在标记后解析;我在上面的代码中尝试了SimpleXMLElement,但它不起作用。我认为这是因为Service type=object上的属性,但我不知道如何访问它。 <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap
为什么不使用SoapClient呢?否则,响应可以由SimpleXML在
标记后解析;我在上面的代码中尝试了SimpleXMLElement,但它不起作用。我认为这是因为Service type=object上的属性,但我不知道如何访问它。
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<rateresp:RateResponse xmlns:rateresp="http://scxgxtt.phx-dc.dhl.com/euExpressRateBook/RateMsgResponse">
<Provider code="DHL">
<Notification code="0">
<Message/>
</Notification>
<Service type="C">
<TotalNet>
<Currency>EUR</Currency>
<Amount>436.16</Amount>
</TotalNet>
<Charges>
<Currency>EUR</Currency>
<Charge>
<ChargeType>MEDICAL EXPRESS</ChargeType>
<ChargeAmount>392.94</ChargeAmount>
</Charge>
<Charge>
<ChargeType>FUEL SURCHARGE</ChargeType>
<ChargeAmount>43.22</ChargeAmount>
</Charge>
</Charges>
<DeliveryTime>2015-05-19T09:00:00</DeliveryTime>
<CutoffTime>2015-05-18T18:30:00</CutoffTime>
<NextBusinessDayInd>N</NextBusinessDayInd>
</Service>
<Service type="K">
<TotalNet>
<Currency>EUR</Currency>
<Amount>415.35</Amount>
</TotalNet>
<Charges>
<Currency>EUR</Currency>
<Charge>
<ChargeType>EXPRESS 9:00</ChargeType>
<ChargeAmount>374.19</ChargeAmount>
</Charge>
<Charge>
<ChargeType>FUEL SURCHARGE</ChargeType>
<ChargeAmount>41.16</ChargeAmount>
</Charge>
<Charge>
<ChargeType>9:00 PREMIUM</ChargeType>
<ChargeAmount>0.00</ChargeAmount>
</Charge>
</Charges>
<DeliveryTime>2015-05-19T09:00:00</DeliveryTime>
<CutoffTime>2015-05-18T18:30:00</CutoffTime>
<NextBusinessDayInd>N</NextBusinessDayInd>
</Service>
</Provider>
</rateresp:RateResponse>
$element = new SimpleXMLElement($returned);
$element->registerXPathNamespace('r', 'http://scxgxtt.phx-dc.dhl.com/euExpressRateBook/RateMsgResponse');
$result = $element->xpath('//r:Service');
foreach ($result as $Service) {
echo $Service . "\n";
}