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.
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.
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.
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".
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.
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...
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With