ZVON > Tutorials > XML Schema and Relax NG Tutorial
Index | >> Example 1 / 4 << | Prev | Next |
Contents > Naming and definitions > definition of a simpleType, target namespace is null

definition of a simpleType, target namespace is null

  1. XML Schema
  2. Relax NG
XML Schema keys: type, simpleType
Relax NG keys: define, ref

1. XML Schema

We will create our own simpleType, based on integer. The element "root" must be of that type.

Valid document


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

Invalid document
That's not an integer.


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

Correct XML Schema (correct_0.xsd)
The "myInteger" simpleType is from null namespace and thus referenced without prefix.


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

  <xsd:element name="root" type="myInteger"/>

  <xsd:simpleType name="myInteger">
    <xsd:restriction base="xsd:integer"/>
  </xsd:simpleType>
</xsd:schema>

2. Relax NG

The naming of RelaxNG patterns is by no means bound to namespace.

Valid document


<root xmlns="">24</root>

Invalid document
That's not an integer.


<root xmlns="">abc</root>

Correct Relax NG schema (correctRelax_0.rng)


<grammar datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes" xmlns="http://relaxng.org/ns/structure/1.0" >

  <start>
    <element>
      <name ns="">root</name>
      <ref name="myInteger"/>
    </element>
  </start>

  <define name="myInteger">
    <data type="integer"/>
  </define>
</grammar>