ZVON > Tutorials > XML Schema and Relax NG Tutorial |
Intro / Search / ZVON |
Index | >> Example 2 / 2 << | Prev | Next | |
We can change the type of the element by setting the value of "xsi:type" attribute. The new type must be validly derived from the overridden type. Validation Rule: Element Locally Valid (Element) .
Valid document <root xsi:noNamespaceSchemaLocation="correct_0.xsd" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > <e>123.4</e> </root> Valid document <root xsi:noNamespaceSchemaLocation="correct_0.xsd" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" > <e xsi:type="myInteger">10</e> </root> Invalid document <root xsi:noNamespaceSchemaLocation="correct_0.xsd" xsi:nil="true" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > <e1 xsi:type="myFloat">1.2e+3</e1> </root> |
Correct XML Schema (correct_0.xsd) <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" > <xsd:element name="root"> <xsd:complexType> <xsd:sequence> <xsd:element name="e" type="xsd:decimal"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:simpleType name="myInteger"> <xsd:restriction base="xsd:integer"/> </xsd:simpleType> <xsd:simpleType name="myFloat"> <xsd:restriction base="xsd:float"/> </xsd:simpleType> </xsd:schema> |
There is no such mechanism in Relax NG.