ZVON > Tutorials > XML Schema and Relax NG Tutorial |
Intro / Search / ZVON |
Index | >> Example 2 / 10 << | Prev | Next | |
Restricting simpleType is relatively easy. Here we will require the value of the element "root" to be integer and less than 25.
Valid document <root xsi:noNamespaceSchemaLocation="correct_0.xsd" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >24</root> Invalid 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"> <xsd:simpleType> <xsd:restriction base="xsd:integer"> <xsd:maxExclusive value="25"/> </xsd:restriction> </xsd:simpleType> </xsd:element> </xsd:schema> |
Relax NG can use the XML Schema datatypes. They can be imported using the "datatypeLibrary" attribute. Restrictions are performed using the "param" element. Let's have the same example as above - "root" must be an integer and less than 25.
Valid document <root xmlns="">24</root> Invalid document <root xmlns="">25</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"> <param name="maxExclusive">25</param> </data> </element> </start> </grammar> Correct Relax NG schema (correctRelax_1.rng) |