Bro*_*shi 0 php xml soap simplexml
namespaces尽管我尝试使用simpleXML 但仍然没有结果,但我不知道如何解析此 XML 响应...有什么想法吗?
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header />
<SOAP-ENV:Body>
<ns3:GetDistrictByAddressResponse xmlns:ns3="http://il/co/bar/webservices/getdistrictbyaddress">
<TimeFrameTable>
<CustomerNumber>250</CustomerNumber>
<Row>
<WindowDate>10052016</WindowDate>
<WeekDay>Sunday</WeekDay>
<FromHour>1130</FromHour>
<ToHour>1430</ToHour>
</Row>
<Row>
<WindowDate>10052016</WindowDate>
<WeekDay>Sunday</WeekDay>
<FromHour>1430</FromHour>
<ToHour>1730</ToHour>
</Row>
</TimeFrameTable>
</ns3:GetDistrictByAddressResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Run Code Online (Sandbox Code Playgroud)
xpath是你的朋友:
xpath('//Row');
Run Code Online (Sandbox Code Playgroud)
完整示例:
$soap = <<< LOL
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header />
<SOAP-ENV:Body>
<ns3:GetDistrictByAddressResponse xmlns:ns3="http://il/co/bar/webservices/getdistrictbyaddress">
<TimeFrameTable>
<CustomerNumber>250</CustomerNumber>
<Row>
<WindowDate>10052016</WindowDate>
<WeekDay>Sunday</WeekDay>
<FromHour>1130</FromHour>
<ToHour>1430</ToHour>
</Row>
<Row>
<WindowDate>10052016</WindowDate>
<WeekDay>Sunday</WeekDay>
<FromHour>1430</FromHour>
<ToHour>1730</ToHour>
</Row>
</TimeFrameTable>
</ns3:GetDistrictByAddressResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
LOL;
$xml = simplexml_load_string($soap);
foreach ($xml->xpath('//Row') as $item)
{
print_r($item);
}
Run Code Online (Sandbox Code Playgroud)
输出:
SimpleXMLElement Object
(
[WindowDate] => 10052016
[WeekDay] => Sunday
[FromHour] => 1130
[ToHour] => 1430
)
SimpleXMLElement Object
(
[WindowDate] => 10052016
[WeekDay] => Sunday
[FromHour] => 1430
[ToHour] => 1730
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7192 次 |
| 最近记录: |