ZVON > Tutorials > XML Schema and Relax NG Tutorial |
Intro / Search / ZVON |
Index | >> Example 1 / 8 << | Prev | Next | |
The element "T" must contain number greater than -273.15. We will define our custom type for temperature named "Temperature" and will require the element "T" to be of that type.
Valid document <T xsi:noNamespaceSchemaLocation="correct_0.xsd" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > -10 </T> Invalid document <T xsi:noNamespaceSchemaLocation="correct_0.xsd" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > -300.1 </T> |
Correct XML Schema (correct_0.xsd) <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" > <xsd:element name="T" type="Temperature"/> <xsd:simpleType name="Temperature"> <xsd:restriction base="xsd:double"> <xsd:minExclusive value="-273.15"/> </xsd:restriction> </xsd:simpleType> </xsd:schema> |
The element "T" must contain number greater than -273.15. We will define a custom pattern named "Temperature" and use it for the definition of the element "T".
Valid document <T xmlns=""> -10 </T> Invalid document <T xmlns=""> -300.1 </T> |
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="">T</name> <ref name="Temperature"/> </element> </start> <define name="Temperature"> <data type="double"> <param name="minExclusive">-273.15</param> </data> </define> </grammar> |