用 simplexml_load_string 进行肥皂解析我想解析它我得到空正文的响应
<?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>
<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>
<?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>
<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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我敢打赌,问题是当您有一个封装在 XML 数据包中的 SOAP 数据时,您可以使用 PHP 中的哪个函数来提取 SOAP 数据?
我刚刚研究了一个小时,因为我遇到了类似的问题。归根结底是,仅仅因为 SOAP 包装在 XML 中并不意味着您可以使用“简单”;-) XML 函数来提取所需的 SOAP 信息。
您必须牢记名称空间。就我而言,我有这样的情况:
我需要提取“Request_MerchantStatementResult”,仅此而已。解决方案是指定我的返回 XML 中引用的名称空间。
如果您只是 print_r simplexml_load_string 的结果,那么问题就出现了,您什么也得不到。因此请务必指定您的名称空间。
编辑
我离题了,而不是
我应该有:
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:
I needed to extract the "Request_MerchantStatementResult" and only that. The solution was to specify the name spaces referenced in my return XML.
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
I should have had: