开发者

xml and namespace anomaly

What is the difference between the following pieces of xml?

The reason I ask is that when I submit the xml to a BPEL process the first and second one work but the last one does not, what is going on?

<!-- imported namespace referenced with prefix -->
<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" xmlns:fxd="http://aaa.yy.zz/Foo">
     <soap:Body>
         <fxd:GSR>
             <aaa>
                 <a>1000000</a>
                 <c>UUU</c>
                 <cp>ZZ</cp>
             </aaa>
             <bbb>
                 <cc>CCC</cc>
                 <v>110005632501</v>
             </bbb>
             <adate>2009-11-04T07:14:44.5814828+02:00</adate>
             <bdate>2009-11-04T07:14:44.5814828+02:00</bdate>
             <m>NNNN</m>
             <p>SSSS</p>
             <r>LLLL</r>
         </fxd:GSR>
     </soap:Body>
    </soap:Envelope>        

<!-- inline imported namespace referenced with a prefix-->
<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>
         <fxd:GSR xmlns:fxd="http://aaa.yy.zz/Foo">
             <aaa>
              开发者_运维知识库   <a>1000000</a>
                 <c>UUU</c>
                 <cp>ZZ</cp>
             </aaa>
             <bbb>
                 <cc>CCC</cc>
                 <v>110005632501</v>
             </bbb>
             <adate>2009-11-04T07:14:44.5814828+02:00</adate>
             <bdate>2009-11-04T07:14:44.5814828+02:00</bdate>
             <m>NNNN</m>
             <p>SSSS</p>
             <r>LLLL</r>
         </fxd:GSR>
     </soap:Body>
</soap:Envelope>


<!-- inline namespace -->
<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>
           <GSR xmlns="http://aaa.yy.zz/Foo">
               <aaa>
                   <a>1000000</a>
                   <c>UUU</c>
                   <cp>ZZ</cp>
               </aaa>
               <bbb>
                   <cc>CCC</cc>
                   <v>110005632501</v>
               </bbb>
               <adate>2009-11-04T07:14:44.5814828+02:00</adate>
               <bdate>2009-11-04T07:14:44.5814828+02:00</bdate>
               <m>NNNN</m>
               <p>SSSS</p>
               <r>LLLL</r>
           </GSR>
       </soap:Body>
</soap:Envelope>

My intuition says they are equivalent pieces of xml, especially considering they come from the same wsdl. They are parsed successfully but the namespaces of the elements are not what they should be.


They are not equal. That is, example 1 and 2 are equal, but 3 is not.

Look at <fxd:GSR> in contrast to <GSR>. You see, that the first one is prefixed. Now, if you define a namespace xmlns:fxd="", all equally prefixed elements are set in this namespace. All others (including elements without any prefix at all) are not in this namespace.

Then, in your third example, you define a namespace for all unprefixed elements. This leads to the fact, that the unprefixed children of GSR are suddenly in the same namespace as their ancestor, not in the nullnamespace they were before in 1 and 2.

Edit: Just a small clarification:

xmlns:fxd="http://aaa.yy.zz/Foo"

sets the namespace to "http://aaa.yy.zz/Foo" for all elements that start with 'fxd:'.

xmlns="http://aaa.yy.zz/Foo"

sets the namespace to "http://aaa.yy.zz/Foo" for all elements that have no colon in their name (= they are not prefixed).

If you want 1 and 2 to behave like 3, just add

xmlns="http://aaa.yy.zz/Foo"

somewhere before the first unprefixed element occurs. If you want it the other way round, you would have to prefix all elements you want to be in no namespace with, say, 'bar:' and add this somewhere:

xmlns:bar=""

thus explicitly setting them in the null namespace (as they are in the first two examples).


in your last sample, wouldn't it put all elements enclosed in the GSR element in the fxd namespace ? in the first 2 samples, those elements enclosed in the GSR element are not in the fxd namespace.

so, i would say the last sample is different from the first 2.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜