ZVON > Tutorials > XML Schema and Relax NG Tutorial
Index | >> Example 1 / 9 << | Prev | Next |
Contents > Simple tasks > Empty element

Empty element

  1. XML Schema
  2. Relax NG

1. XML Schema

We want to have the root element to be named "AAA", from null namespace and empty. The empty element is defined as a "complexType" with a "complexContent" which is a restriction of "anyType", but without any elements.

Valid document


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

Correct XML Schema (correct_0.xsd)


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

  <xsd:element name="AAA">
    <xsd:complexType>
      <xsd:complexContent>
        <xsd:restriction base="xsd:anyType"/>
      </xsd:complexContent>
    </xsd:complexType>
  </xsd:element>
</xsd:schema>

2. Relax NG

To specify, that element must be empty, use the "empty" element.

Valid document


<AAA xmlns=""/>

Correct Relax NG schema (correctRelax_0.rng)


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

  <start>
    <element>
      <name ns="">AAA</name>
      <empty/>
    </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="">AAA</name>
  <empty/>
</element>