ZVON > Tutorials > XML Schema and Relax NG Tutorial
Index | >> Example 1 / 3 << | Prev | Next |
Contents > The namespace of document root element > The document root element is from null namespace

The document root element is from null namespace

  1. XML Schema
  2. Relax NG

Please, send all comments, bug-reports, and contributions to Jiri.Jirat@systinet.com. Thank you very much.

XML Schema keys: targetNamespace
Relax NG keys: ns

1. XML Schema

If we use the attribute "noNamespaceSchemaLocation", we say that the schema is for element from null namespace.

Valid document


<root xsi:noNamespaceSchemaLocation="correct_0.xsd" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > test </root>

Correct XML Schema (correct_0.xsd)
There is no attribute targetNamespace and thus the top-level elements must be from null namespace.


<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" >

  <xsd:element name="root" type="xsd:string"/>
</xsd:schema>

2. Relax NG

See, how easily this can be accomplished using Relax NG. The pattern <name ns="">root</name> says, that the root element must be named "root" and that it must be from null namespace.

Valid document


<root xmlns=""> test </root>

Correct Relax NG schema (correctRelax_0.rng)


<grammar xmlns="http://relaxng.org/ns/structure/1.0" >

  <start>
    <element>
      <name ns="">root</name>
      <text/>
    </element>
  </start>
</grammar>

Correct Relax NG schema (correctRelax_1.rng)
This short version is also valid.


<element xmlns="http://relaxng.org/ns/structure/1.0" >
  <name ns="">root</name>
  <text/>
</element>