Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does xmlns="" exactly mean

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.

like image 309
Raymond Avatar asked Jul 06 '10 07:07

Raymond


People also ask

What is the meaning of xmlns?

An XML namespace is a collection of names that can be used as element or attribute names in an XML document. The namespace qualifies element names uniquely on the Web in order to avoid conflicts between elements with the same name.

Why do we use xmlns?

One of the primary motivations for defining an XML namespace is to avoid naming conflicts when using and re-using multiple vocabularies. XML Schema is used to create a vocabulary for an XML instance, and uses namespaces heavily.

Where is xmlns defined?

XML Namespaces - The xmlns Attribute When using prefixes in XML, a namespace for the prefix must be defined. The namespace can be defined by an xmlns attribute in the start tag of an element. The namespace declaration has the following syntax. xmlns:prefix="URI".

What is xmlns in XML Schema?

Namespaces are a mechanism for breaking up your schemas. Up until now we have assumed that you only have a single schema file containing all your element definitions, but the XSD standard allows you to structure your XSD schemas by breaking them into multiple files.


2 Answers

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

like image 107
Tomek Szpakowicz Avatar answered Sep 29 '22 08:09

Tomek Szpakowicz


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

like image 21
Donal Fellows Avatar answered Sep 29 '22 06:09

Donal Fellows