ZVON > Tutorials > XML Schema and Relax NG Tutorial
Index | >> Example 1 / 10 << | Prev | Next |
Contents > Simple types > Accessing data-types

Accessing data-types

  1. XML Schema (XML Schema namespace is not default)
  2. XML Schema (XML Schema namespace is default)
  3. Relax NG
XML Schema keys: type
Relax NG keys: datatype

1. XML Schema (XML Schema namespace is not default)

In XML Schema, the datatype is referenced by the QName. The namespace must be mapped to the prefix.

Valid document


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

Correct XML Schema (correct_0.xsd)


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

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

2. XML Schema (XML Schema namespace is default)

In XML Schema, the datatype is referenced by the QName. If the XML Schema is the default namespace, then you can reference the datatypes without a prefix.

Valid document


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

Correct XML Schema (correct_0.xsd)


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

  <element name="root" type="integer"/>
</schema>

3. Relax NG

Relax NG can use the XML Schema datatypes. They can be imported using the "datatypeLibrary" attribute.

Valid document


<root xmlns="">10</root>

Invalid document
This is not an integer.


<root xmlns="">1.5</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>
      <data type="integer"/>
    </element>
  </start>
</grammar>

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


<element ns="" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes" name="root" xmlns="http://relaxng.org/ns/structure/1.0" >
  <data type="integer"/>
</element>