ZVON > Tutorials > XML Schema and Relax NG Tutorial
Index | >> Example 3 / 4 << | Prev | Next |
Contents > elementFormDefault - elements > elementFormDefault unqualified for not-top-level elements, namespace non-null

elementFormDefault unqualified for not-top-level elements, namespace non-null

  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: elementFormDefault
Relax NG keys: ns

1. XML Schema

Now let's have a child element. Because the attribute "elementFormDefault" is set to "unqualified", the child must be from the null namespace.

Valid document


<root xsi:schemaLocation="http://foo correct_0.xsd" xmlns="http://foo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
  <e1 xmlns="">Element 1</e1>
</root>

Correct XML Schema (correct_0.xsd)


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

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

2. Relax NG

We can set the namespace using the "ns" attribute. Here the "name" element does not have "ns" attribute, and thus it is inherited from nearest ancestor (which has "ns" attribute).

Valid document


<root xmlns="http://foo" >
  <e1 xmlns="">Element 1</e1>
</root>

Correct Relax NG schema (correctRelax_0.rng)


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

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