为什么这些xml文件会得到不同的响应?

时间:2015-06-18 17:34:31

标签: java xml web-services xmlhttprequest

这两个xml文件是否意思相同?

第一档:

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" >
   <S:Body>
      <ProcessData xmlns="http://arinc/asd/OnvoyRegistration">
         <document><request xmlns="http://arinc/asd/OnvoyRegistration">
        <hotelChain>Disney</hotelChain>
        <processType>ModifyGuest</processType>
        <hotelLineId>ASMU03042015</hotelLineId>
        <firstName>NICOLE</firstName>
        <lastName>ROLAIN</lastName>
        <numberOfBags>1</numberOfBags>
        <status>enrolled</status>
        <hotelGuestId>41955886</hotelGuestId>
        <room>5613</room>
        <eligible>1</eligible>
        <partyGroupId>0</partyGroupId>
        <arrivalDate>2015-02-26</arrivalDate>
        <departureDate>2015-03-04</departureDate>
        <segments>
          <segment>
              <carrier>WN</carrier>
              <flightNumber>4280</flightNumber>
              <departureCity>MCO</departureCity>
              <departureDate>2015-03-04</departureDate>
              <departureTime>12:00 PM</departureTime>
              <operation>Add</operation>
           </segment>
        </segments>
    </request>
    </document>
      </ProcessData>
   </S:Body>
</S:Envelope>

响应:

<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>
      <ProcessDataResponse xmlns="http://arinc/asd/OnvoyRegistration">
         <ProcessDataResult>
            <response xmlns="">Invalid Process Type</response>
         </ProcessDataResult>
      </ProcessDataResponse>    </soap:Body> </soap:Envelope>

第二档:

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" xmlns:onv="http://arinc/asd/OnvoyRegistration">
   <S:Body>
      <onv:ProcessData>
         <onv:document><request>
        <hotelChain>Disney</hotelChain>
        <processType>ModifyGuest</processType>
        <hotelLineId>ASMU03042015</hotelLineId>
        <firstName>NICOLE</firstName>
        <lastName>ROLAIN</lastName>
        <numberOfBags>1</numberOfBags>
        <status>enrolled</status>
        <hotelGuestId>41955886</hotelGuestId>
        <room>5613</room>
        <eligible>1</eligible>
        <partyGroupId>0</partyGroupId>
        <arrivalDate>2015-02-26</arrivalDate>
        <departureDate>2015-03-04</departureDate>
        <segments>
          <segment>
              <carrier>WN</carrier>
              <flightNumber>4280</flightNumber>
              <departureCity>MCO</departureCity>
              <departureDate>2015-03-04</departureDate>
              <departureTime>12:00 PM</departureTime>
              <operation>Add</operation>
           </segment>
        </segments>
    </request>
    </onv:document>
      </onv:ProcessData>
   </S:Body>
</S:Envelope>

响应:

<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>
      <ProcessDataResponse xmlns="http://arinc/asd/OnvoyRegistration">
         <ProcessDataResult>
            <response xmlns="">OK</response>
         </ProcessDataResult>
      </ProcessDataResponse>
   </soap:Body>
</soap:Envelope>

我认为这两个XML文件代表相同的信息。但是,当我使用这两个文件访问SOAP Web服务时,我得到了不同的响应。

我也试过这个:

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" xmlns:onv="http://arinc/asd/OnvoyRegistration">
   <S:Body>
      <onv:ProcessData>
         <onv:document><onv:request>
        <onv:hotelChain>Disney</onv:hotelChain>
        <onv:processType>ModifyGuest</onv:processType>
        <onv:hotelLineId>ASMU03042015</onv:hotelLineId>
        <onv:firstName>NICOLE</onv:firstName>
        <onv:lastName>ROLAIN</onv:lastName>
        <onv:numberOfBags>1</onv:numberOfBags>
        <onv:status>enrolled</onv:status>
        <onv:hotelGuestId>41955886</onv:hotelGuestId>
        <onv:room>5613</onv:room>
        <onv:eligible>1</onv:eligible>
        <onv:partyGroupId>0</onv:partyGroupId>
        <onv:arrivalDate>2015-02-26</onv:arrivalDate>
        <onv:departureDate>2015-03-04</onv:departureDate>
        <onv:segments>
          <onv:segment>
              <onv:carrier>WN</onv:carrier>
              <onv:flightNumber>4280</onv:flightNumber>
              <onv:departureCity>MCO</onv:departureCity>
              <onv:departureDate>2015-03-04</onv:departureDate>
              <onv:departureTime>12:00 PM</onv:departureTime>
              <onv:operation>Add</onv:operation>
           </onv:segment>
        </onv:segments>
    </onv:request>
    </onv:document>
      </onv:ProcessData>
   </S:Body>
</S:Envelope>

响应:

<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>
      <ProcessDataResponse xmlns="http://arinc/asd/OnvoyRegistration">
         <ProcessDataResult>
            <response xmlns="">Invalid Process Type</response>
         </ProcessDataResult>
      </ProcessDataResponse>
   </soap:Body>
</soap:Envelope>

1 个答案:

答案 0 :(得分:1)

不,他们不一样。

没有前缀的名称空间声明声明了所谓的默认名称空间。默认命名空间应用于声明它的元素和所有子元素。

所以在以下XML片段中

<parent xmlns="namespace">
    <child />
</parent>

both - parent元素和子元素都在给定的命名空间中。

另一方面,在以下XML片段中

<pre:parent xmlns:pre="namespace">
    <child />
</pre:parent>

你有一个用前缀声明的命名空间。此命名空间仅适用于显式携带该前缀的那些元素。在此示例中,它只是parent元素,而child元素没有命名空间。

在您的XML文档中,您有类似的情况:

<ProcessData xmlns="http://arinc/asd/OnvoyRegistration">
    <document>
        <request xmlns="http://arinc/asd/OnvoyRegistration">
            ...
        </request>
    </document>
</ProcessData>

<onv:ProcessData>
     <onv:document>
         <request>
            ...
        </request>
    </onv:document>
</onv:ProcessData>

前缀onv表示与上面相同的命名空间。

在第二个文档中,request元素由于缺少前缀而没有命名空间。在第一个文档中,它位于层次结构中声明稍高的默认命名空间中。实际上,request元素的名称空间声明是多余的(在第一个文档中)。