ZVON > Tutorials > XML Schema and Relax NG Tutorial |
Intro / Search / ZVON |
Index | >> Example 4 / 10 << | Prev | Next | |
Now, we want the element "root" to be either an integer or a string "N/A". We will make a union from an "integer" type and "string" type.
Valid document <root xsi:noNamespaceSchemaLocation="correct_0.xsd" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >50</root> Valid document <root xsi:noNamespaceSchemaLocation="correct_0.xsd" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >N/A</root> Invalid document <root xsi:noNamespaceSchemaLocation="correct_0.xsd" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >#REF!</root> |
Correct XML Schema (correct_0.xsd) <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" > <xsd:element name="root"> <xsd:simpleType> <xsd:union> <xsd:simpleType> <xsd:restriction base="xsd:integer"/> </xsd:simpleType> <xsd:simpleType> <xsd:restriction base="xsd:string"> <xsd:enumeration value="N/A"/> </xsd:restriction> </xsd:simpleType> </xsd:union> </xsd:simpleType> </xsd:element> </xsd:schema> |
As in previous example, we will use the "choice" element.
Valid document <root xmlns="">50</root> Valid document <root xmlns="">N/A</root> Invalid document <root xmlns="">#REF!</root> |
Correct Relax NG schema (correctRelax_0.rng) |