views:

62

answers:

2

Given the following (piece of) a soap call;

<m1:NextCommencementDateInput xmlns:m1="http://foo.bar.com/Types"&gt;
    <aDate xmlns="">2010-06-02</aDate>
</m1:NextCommencementDateInput>

Apperantly this is the same as (when validating against the xsd using XMLSpy)

<m1:NextCommencementDateInput xmlns:m1="http://foo.bar.com/Types"&gt;
    <aDate>2010-06-02</aDate>
</m1:NextCommencementDateInput>

So what does xmlns="" do exactly ?

Edit: To elaborate why I'm asking this is because I'm calling a third party and they are now stating that we should remove xmlns="" from our requests. I however think they are the same and they should change their side.

+1  A: 

According to the XML Namespace specification (§6.2), they are completely identical other than for the extra attribute itself (which your implementation may or may not hide from you).

Donal Fellows
According to the spec that you link to they are *not* the same (but it would depend on the surrounding XML).
0xA3
That would indeed depend on the context. I was taking the example as a whole document.
Donal Fellows
+2  A: 

xmlns="" clears definition of default namespace (aka empty prefix). After this declaration all elements without prefix are considered to have null namespace.

So the difference is:

  • First example (with xmlns="") clears empty prefix so aDate element has null namespace.

  • Second example doesn't clear it. Namespace of aDate element depends on namespace declaration in containing scope. If there is active xmlns="some:namespace" declaration, aDate will have this namespace. Otherwise it will have null namespace.

Additionally some XML parsers complain on xmlns="" if there is no active xmlns="some:namespace" declaration to clear...

Tomek Szpakowicz