ZVON > Tutorials > XML Schema and Relax NG Tutorial |
Intro / Search / ZVON |
Index | >> Example 3 / 6 << | Prev | Next | |
Please, send all comments, bug-reports, and contributions to Jiri.Jirat@systinet.com. Thank you very much.
XML Schema keys: uniqueIn all checkings of "key", "unique", and "keyref" the values are compared, not string-values.
Valid document <root xsi:noNamespaceSchemaLocation="correct_0.xsd" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > <a val="1.0"/> <a val="2"/> <a val="3.5"/> </root> Invalid document <root xsi:noNamespaceSchemaLocation="correct_0.xsd" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > <a val="1"/> <a val="1.0"/> <a val="2"/> </root> |
Correct XML Schema (correct_0.xsd) <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" > <xsd:element name="root" type="myList"> <xsd:unique name="myId"> <xsd:selector xpath="./a"/> <xsd:field xpath="@val"/> </xsd:unique> </xsd:element> <xsd:complexType name="myList"> <xsd:sequence minOccurs="1"> <xsd:element name="a" minOccurs="1" maxOccurs="unbounded"> <xsd:complexType> <xsd:attribute name="val" type="xsd:decimal"/> </xsd:complexType> </xsd:element> </xsd:sequence> </xsd:complexType> </xsd:schema> |
Schematron uses XPath functions, so we can force the conversion to a number.
Valid document <root xmlns=""> <a val="1.0"/> <a val="2"/> <a val="3.5"/> </root> Invalid document <root xmlns=""> <a val="1"/> <a val="1.0"/> <a val="2"/> </root> |
Correct Relax NG schema (correctRelax_0.rng) <grammar datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes" ns="" xmlns="http://relaxng.org/ns/structure/1.0" > <start> <element name="root"> <oneOrMore> <element name="a"> <optional> <attribute name="val"> <data type="decimal"/> </attribute> </optional> <empty/> </element> </oneOrMore> </element> </start> </grammar> Correct Schematron schema |