Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何从soapxml响应中获取city_Php_Xml_Soap - Fatal编程技术网

Php 如何从soapxml响应中获取city

Php 如何从soapxml响应中获取city,php,xml,soap,Php,Xml,Soap,嗨,我正在使用curl获得soap响应。我正在尝试从soap获取city,下面的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

嗨,我正在使用curl获得soap响应。我正在尝试从soap获取city,下面的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>`
谁能告诉我,我哪里做错了。我试过很多方法来得到结果


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

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

$parser = simplexml_load_string($response4);
$rentalStations = $parser->xpath('//RentalStations/Table');
$cities = [];
foreach ($rentalStations as $rentalStation) {
    $cities[] = (string)$rentalStation->City;
}
var_dump($cities);
$parser = simplexml_load_string($response4);
$rentalStations = $parser->xpath('//RentalStations/Table');
$cities = [];
foreach ($rentalStations as $rentalStation) {
    $cities[] = (string)$rentalStation->City;
}
var_dump($cities);