5

Given the following (piece of) a soap call;

<m1:NextCommencementDateInput xmlns:m1="http://foo.bar.com/Types">
    <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">
    <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.

Raymond
  • 296
  • 3
  • 5
  • 13
  • 1
    possible duplicate of [what is the exact usage of xmlns in xml, and html](http://stackoverflow.com/questions/1372064/what-is-the-exact-usage-of-xmlns-in-xml-and-html) – kennytm Jul 06 '10 at 07:54
  • (Also relevant: http://stackoverflow.com/questions/630468/what-is-xmlns-in-every-wpf-file) – kennytm Jul 06 '10 at 07:54
  • 3
    I don't think this is a duplicate. Raymond ask about specific use of xmlns while the links you provided are talking about xmlns in general. – maayank Jul 06 '10 at 08:16
  • 2
    Indeed, I understand the usage of xmlns, however I'm puzzled with the empty namespace. – Raymond Jul 06 '10 at 08:27

2 Answers2

6

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
  • 14,063
  • 3
  • 33
  • 55
1

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
  • 133,037
  • 18
  • 149
  • 215