views:

45

answers:

2

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"&gt;
     <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"&gt;
     <soap:Body>
         <fxd:GSR xmlns:fxd="http://aaa.yy.zz/Foo"&gt;
             <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"&gt;
       <soap:Body>
           <GSR xmlns="http://aaa.yy.zz/Foo"&gt;
               <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.

A: 

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.

Adrien Plisson
+1  A: 

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).

Boldewyn
so what you're saying then is specifying the namespace of GSR inline as in 3 is _not_ equal to referencing it via a prefix. And this is consistent with the results of the testing that I've been doing.Since they are generated from the same wsdl can you think of any reason why the anomaly is present? Is there some configuration setting or something? 1 + 2 are from Java (Jax-ws) and 3 is from a .net client
Michael Wiles
You should read the spec: http://www.w3.org/TR/xml-names/ XML Namespaces can be a bit tricky, but the spec is quite nice to read (for a spec). Actually, I have no experience with Java, .NET or WSDL. I just know XML namespaces from other contexts (mainly RDF and XHTML+SVG). Sorry, if I can't help you with that.
Boldewyn
By the way: What *would* be the desired outcome: 1 and 2 or 3?
Boldewyn