ZVON > Tutorials > XML Schema and Relax NG Tutorial
Index | >> Example 3 / 3 << | Prev | Next |
Contents > Associating schema with document > Document root element can be from a set of namespaces

Document root element can be from a set of namespaces

  1. XML Schema
  2. Relax NG

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

Relax NG keys: ns, choice

1. XML Schema

We allow the "root" element to be from several namespaces, let's say: "http://foo", "http://bar", or "http://baz". That's not possible in XML Schema.


2. Relax NG

The treating of namespaces in Relax NG is smooth, consistent, natural, and easy.

Valid document


<root xmlns="http://foo" >aaa</root>

Valid document


<root xmlns="http://baz" >bbb</root>

Correct Relax NG schema (correctRelax_0.rng)


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

  <start>
    <element>
      <choice>
        <name ns="http://foo">root</name>
        <name ns="http://bar">root</name>
        <name ns="http://baz">root</name>
      </choice>
      <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" >
  <choice>
    <name ns="http://foo">root</name>
    <name ns="http://bar">root</name>
    <name ns="http://baz">root</name>
  </choice>
  <text/>
</element>