soap parsing with simplexml_load_string i want to parse it i get response with empty body
<?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>
<SearchHotelsResponse xmlns="http://tourico.com/webservices/">
<SearchHotelsResult>
<xs:schema id="TWS_HotelList" targetNamespace="http://tourico.com/webservices/TWS_HotelList.xsd" xmlns:mstns="http://tourico.com/webservices/TWS_HotelList.xsd" xmlns="http://tourico.com/webservices/TWS_HotelList.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:msprop="urn:schemas-microsoft-com:xml-msprop" attributeFormDefault="qualified" elementFormDefault="qualified">
<xs:element name="TWS_HotelList" msdata:IsDataSet="true" msdata:Locale="en-US" msdata:EnforceConstraints="False">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="Hotel">
<xs:complexType>
<xs:sequence>
开发者_StackOverflow社区 <xs:element name="RoomType" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Avail" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="offset" form="unqualified" type="xs:byte" use="required" />
<xs:attribute name="status" form="unqualified" type="xs:boolean" use="required" /></xs:complexType>
</xs:element>
<xs:element name="Discount" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="type" form="unqualified" msprop:Generator_UserColumnName="type" msprop:Generator_ColumnVarNameInTable="columtype" type="xs:string" use="required" />
<xs:attribute name="name" form="unqualified" type="xs:string" use="required" />
<xs:attribute name="from" form="unqualified" msdata:DateTimeMode="Unspecified" type="xs:dateTime" use="required" />
<xs:attribute name="to" form="unqualified" msdata:DateTimeMode="Unspecified" type="xs:dateTime" use="required" />
<xs:attribute name="value" form="unqualified" type="xs:string" use="required" /></xs:complexType>
</xs:element>
<xs:element name="Occup" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Supp" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="supId" form="unqualified" type="xs:int" />
<xs:attribute name="name" form="unqualified" type="xs:string" use="required" />
<xs:attribute name="price" form="unqualified" type="xs:double" use="required" /></xs:complexType>
</xs:element>
<xs:element name="Board" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="bbId" form="unqualified" type="xs:int" />
<xs:attribute name="name" form="unqualified" type="xs:string" use="required" />
<xs:attribute name="price" form="unqualified" type="xs:double" use="required" />
<xs:attribute name="default" form="unqualified" msprop:Generator_UserColumnName="default" msprop:Generator_ColumnVarNameInTable="columndefault" msprop:Generator_ColumnPropNameInTable="defaultColumn"
type="xs:boolean" default="false" /></xs:complexType>
</xs:element>
<xs:element name="Room" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Child" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="age" form="unqualified" type="xs:int" /></xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="seqNum" form="unqualified" type="xs:int" use="required" />
<xs:attribute name="adultNum" form="unqualified" type="xs:int" use="required" />
<xs:attribute name="childNum" form="unqualified" type="xs:int" /></xs:complexType>
</xs:element>
<xs:element name="Price" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="offset" form="unqualified" type="xs:int" use="required" />
<xs:attribute name="value" form="unqualified" type="xs:double" use="required" /></xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="occupId" form="unqualified" type="xs:string" use="required" />
<xs:attribute name="maxAdult" form="unqualified" type="xs:int" use="required" />
<xs:attribute name="maxChild" form="unqualified" type="xs:int" use="required" />
<xs:attribute name="price" form="unqualified" type="xs:double" use="required" />
<xs:attribute name="tax" form="unqualified" type="xs:double" use="required" />
<xs:attribute name="dblBed" form="unqualified" type="xs:boolean" />
<xs:attribute name="avrNightPrice" form="unqualified" type="xs:double" use="required" /></xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="productId" form="unqualified" type="xs:string" use="required" />
<xs:attribute name="name" form="unqualified" type="xs:string" use="required" />
<xs:attribute name="nights" form="unqualified" type="xs:byte" use="required" />
<xs:attribute name="startDate" form="unqualified" type="xs:dateTime" use="required" />
<xs:attribute name="isAvailable" form="unqualified" type="xs:boolean" />
<xs:attribute name="roomId" form="unqualified" type="xs:int" />
<xs:attribute name="hotelRoomTypeId" form="unqualified" type="xs:int" /></xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="hotelId" form="unqualified" type="xs:int" use="required" />
<xs:attribute name="provider" form="unqualified" type="xs:string" use="required" />
<xs:attribute name="name" form="unqualified" type="xs:string" use="required" />
<xs:attribute name="address" form="unqualified" type="xs:string" />
<xs:attribute name="category" form="unqualified" type="xs:string" />
<xs:attribute name="bestVal" form="unqualified" type="xs:byte" />
<xs:attribute name="thumb" form="unqualified" type="xs:string" />
<xs:attribute name="starsLevel" form="unqualified" type="xs:double" />
<xs:attribute name="minAverPrice" form="unqualified" type="xs:double" use="required" />
<xs:attribute name="desc" form="unqualified" type="xs:string" use="required" />
<xs:attribute name="location" form="unqualified" type="xs:string" use="required" />
<xs:attribute name="currency" form="unqualified" type="xs:string" />
<xs:attribute name="brandId" form="unqualified" type="xs:int" />
<xs:attribute name="brandName" form="unqualified" type="xs:string" /></xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<TWS_HotelList xmlns="http://tourico.com/webservices/TWS_HotelList.xsd">
<Hotel hotelId="1041291" provider="localTgsProvider" name="Rush Inn - DEMO - DEMO" address="DEMO - Khalid Bin Waleed Road Dubai 44099" category="Tourist Class" bestVal="0" thumb="http://image1.urlforimages.com/1041291/Rush-Front_Thumbnailed.jpg"
starsLevel="2" minAverPrice="148.54" desc="DEMO - DEMO - Families will love to vacation at the Rush Inn with all the amenities and attractions it provides" location="Bur Dubai,Dubai,AE" currency="AED" brandId="0" brandName="">
<RoomType productId="1041291;1180012;34538" name="Standard" nights="1" startDate="2010-08-20T00:00:00-04:00" isAvailable="true" roomId="3" hotelRoomTypeId="1180012">
<Avail offset="0" status="true" />
<Occup occupId="1041291;1180012;34538;2;2;0;1" maxAdult="4" maxChild="2" price="148.54" tax="0" dblBed="true" avrNightPrice="148.54">
<Board bbId="24" name="Room Only" price="0" default="true" />
<Room seqNum="1" adultNum="1" childNum="1">
<Child age="8" />
</Room>
<Price offset="0" value="148.54" />
</Occup>
<Occup occupId="1041291;1180012;34538;2;2;0;2" maxAdult="4" maxChild="2" price="148.54" tax="0" dblBed="false" avrNightPrice="148.54">
<Board bbId="24" name="Room Only" price="0" default="true" />
<Room seqNum="1" adultNum="1" childNum="1">
<Child age="8" />
</Room>
<Price offset="0" value="148.54" />
</Occup>
</RoomType>
</Hotel>
</TWS_HotelList>
</SearchHotelsResult>
</SearchHotelsResponse>
</soap:Body>
</soap:Envelope>
My bet is the question is when you have a SOAP data which is wrapped in an XML packet which function in PHP can you use to extract SOAP data?
I just researched this for an hour because I had a similar issue. What is boils down to is that just because SOAP is wrapped in XML doesn't mean you can use a "simple" ;-) XML function to extract the SOAP information that you want.
You have to bear namespaces in mind. In my case I had this:
<?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><Request_MerchantStatementResponse xmlns="http://www.netcash.co.za/netserv/ncUpload">
* <Request_MerchantStatementResult>2010/11/06 00:00:00\tOBL\t0\t\tOpening Balance\t100000.00\t+\t0.00\t\t\t\t\t\t\t\r</Request_MerchantStatementResult>
* </Request_MerchantStatementResponse></soap:Body>
* </soap:Envelope>
I needed to extract the "Request_MerchantStatementResult" and only that. The solution was to specify the name spaces referenced in my return XML.
$xml = simplexml_load_string($response);
echo $xml->children('http://schemas.xmlsoap.org/soap/envelope/')
->children('http://www.netcash.co.za/netserv/ncUpload')
->Request_MerchantStatementResponse
->Request_MerchantStatementResult;
The problem comes in if you just print_r the result from simplexml_load_string you get nothing. So be sure to specify your name space.
EDIT
I digress, instead of having
echo $xml->children('http://schemas.xmlsoap.org/soap/envelope/')
->children('http://www.netcash.co.za/netserv/ncUpload')
->Request_MerchantStatementResponse
->Request_MerchantStatementResult;
I should have had:
$result = $xml->children('http://schemas.xmlsoap.org/soap/envelope/')
->children('http://www.netcash.co.za/netserv/ncUpload')
->Request_MerchantStatementResponse;
echo $result->Request_MerchantStatementResult;
精彩评论