Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is xmlns="" a valid xml namespace?

Is "empty" a valid value for XML namespace? If yes what does it mean?

I have the following XML code but I'm not sure to which namespace Field1 and Field2 elements belong to.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
  <soapenv:Header />
  <soap:Body>
    <Root xmlns="uri">
      <Field1 xmlns="">147079737</Field1>
      <Field2 xmlns="">POL</Field2>
    </Root>
  </soap:Body>
</soapenv:Envelope>
like image 661
Sergej Andrejev Avatar asked Oct 19 '09 10:10

Sergej Andrejev


People also ask

What is xmlns in XML?

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

Why do we use xmlns in XML?

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.

What is the default namespace in XML?

When you use multiple namespaces in an XML document, you can define one namespace as the default namespace to create a cleaner looking document. The default namespace is declared in the root element and applies to all unqualified elements in the document. Default namespaces apply to elements only, not to attributes.

Is xmlns an attribute?

Definition and Usage. The xmlns attribute specifies the xml namespace for a document. Note: The xmlns attribute is required in XHTML, invalid in HTML 4.01, and optional in HTML5.


2 Answers

Yes, it is valid. Section 6.2 in the Namespaces in XML 1.0 Recommendation specifically says:

The attribute value in a default namespace declaration MAY be empty. This has the same effect, within the scope of the declaration, of there being no default namespace.

Quoted from comment:

It is legal, and this is the way to bring an element into the global namespace.

like image 126
Frerich Raabe Avatar answered Oct 06 '22 00:10

Frerich Raabe


It is not a valid XML NS. It is not a valid XML NS declaration. Please check section 2.2 of Namespaces in XML 1.0 :

The empty string, though it is a legal URI reference, cannot be used as a namespace name.

It is however the only way to undeclare a default NS declaration if there is one in effect, or it has no effect. See Namespaces in XML 1.0 and 1.1, section 6.2. The 1.1 NS rec added a way to also undeclare a NS declaration with a prefix.

Thus it is a valid value for the xmlns special attribute, but it is not "a valid XML namespace" like the OP wrote it.

like image 40
Ludovic Kuty Avatar answered Oct 06 '22 00:10

Ludovic Kuty