如何从Soap xml响应中获取城市

时间:2018-07-31 04:52:30

标签: php xml soap

嗨,我正在使用卷发器来获得肥皂响应。我正在尝试从soap xml响应中获取城市,以下是我得到的xml响应。

`<?xml version="1.0" encoding="utf-8"?>
<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>
<getStationsResponse xmlns="http://www.jimpisoft.pt/Rentway_Reservations_WS/getStations">
  <getStationsResult>
    <stations>
      <xs:schema id="RentalStations" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
      <xs:element name="RentalStations" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
      <xs:complexType><xs:choice minOccurs="0" maxOccurs="unbounded"><xs:element name="Table">
      <xs:complexType><xs:sequence><xs:element name="StationID" type="xs:string" minOccurs="0" /><xs:element name="Station" type="xs:string" minOccurs="0" />
      <xs:element name="Zone" type="xs:int" minOccurs="0" />
      <xs:element name="StationType" type="xs:int" minOccurs="0" />
      <xs:element name="CountryID" type="xs:int" minOccurs="0" />
      <xs:element name="City" type="xs:string" minOccurs="0" />
      <xs:element name="SupplierID" type="xs:int" minOccurs="0" />
      <xs:element name="Latitude" type="xs:decimal" minOccurs="0" />
      <xs:element name="Longitude" type="xs:decimal" minOccurs="0" />
    </xs:sequence>
  </xs:complexType>
  </xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<RentalStations xmlns="">
  <Table diffgr:id="Table1" msdata:rowOrder="0">
    <StationID>MBAC01</StationID>
    <Station>Mombasa Trade Center     </Station>
    <Zone>1</Zone>
    <StationType>1</StationType>
    <CountryID>1</CountryID>
    <City>MOMBASA</City>
    <Latitude>0.00000</Latitude>
    <Longitude>0.00000</Longitude>
  </Table>
  <Table diffgr:id="Table2" msdata:rowOrder="1">
    <StationID>NBOT01</StationID>
    <Station>Nairobi Airport  JKIA    </Station>
    <Zone>1</Zone>
    <StationType>2</StationType>
    <CountryID>1</CountryID>
    <City>NAIROBI</City>
    <Latitude>0.00000</Latitude>
    <Longitude>0.00000</Longitude>
  </Table>
</RentalStations>
</diffgr:diffgram>
</stations>
</getStationsResult>
</getStationsResponse>
</soap:Body>
</soap:Envelope>`

我正在使用下面的代码来获取城市

$parser = simplexml_load_string($response4);
foreach($parser->getStationsResponse->getStationsResult->stations->diffgr->RentalStations->Table as $od){
    $abf = $od->city;
    echo "city name is".$abf;
}

有人可以告诉我,我在哪里做错了。我尝试了很多方法来获得结果。

还有没有其他方法可以得到结果。

1 个答案:

答案 0 :(得分:1)

您可以使用xpath从XML获取城市。

ISiloHostBuilder