| ZVON > Tutorials > XML Schema and Relax NG Tutorial |
| Intro / Search / ZVON |
| Index | >> Example 7 / 8 << | Prev | Next | |
Please, send all comments, bug-reports, and contributions to Jiri.Jirat@systinet.com. Thank you very much.
XML Schema keys: duration, minInclusive, maxInclusiveThe element "A" must represents time duration, which is from one day to one week. We will define our custom type named "myDuration" and will require the element "A" to be of that type.
|
Valid document <A xsi:noNamespaceSchemaLocation="correct_0.xsd" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >P2DT3H20M</A> Valid document <A xsi:noNamespaceSchemaLocation="correct_0.xsd" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >PT26H</A> Invalid document <A xsi:noNamespaceSchemaLocation="correct_0.xsd" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >PT6H</A> Invalid document <A xsi:noNamespaceSchemaLocation="correct_0.xsd" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >P8D</A> |
Correct XML Schema (correct_0.xsd) <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" > <xsd:element name="A" type="myDuration"/> <xsd:simpleType name="myDuration"> <xsd:restriction base="xsd:duration"> <xsd:minInclusive value="P1D"/> <xsd:maxInclusive value="P7D"/> </xsd:restriction> </xsd:simpleType> </xsd:schema> |
|
Valid document <A xmlns="">P2DT3H20M</A> Valid document <A xmlns="">PT26H</A> Invalid document <A xmlns="">PT6H</A> Invalid document <A xmlns="">P8D</A> |
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="">A</name> <ref name="myDuration"/> </element> </start> <define name="myDuration"> <data type="duration"> <param name="minInclusive">P1D</param> <param name="maxInclusive">P7D</param> </data> </define> </grammar> |