Monday, 29 September 2014

How to use Conditional Type Assignment for different integer types in XSD



XSD1.1 allows the type of an element to depend on one of its attributes. For example,



<element kind='s'>100</element>


will cause the type of 'element' to be xs:short. Here is what I have got:



<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://ift.tt/tphNwY"
xmlns:vc="http://ift.tt/REsXlC"
elementFormDefault="qualified"
attributeFormDefault="unqualified"
vc:minVersion="1.1">
<xs:complexType name="GenericInt">
<xs:simpleContent>
<xs:extension base="xs:integer">
<xs:attribute name="kind" type="xs:string"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:element name="integer" type="GenericInt">
<xs:alternative test="@kind='b'" type="xs:byte"/>
<xs:alternative test="@kind='s'" type="xs:short"/>
<xs:alternative test="@kind='i'" type="xs:int"/>
<xs:alternative test="@kind='l'" type="xs:long"/>
<xs:alternative type="GenericInt"/>
</xs:element>
</xs:schema>


When I tried to save the file in Altova XMLSpy, an error occurred: cos-st-derived-ok.2: Simple type definition 'xs:byte' is not validly derived from 'GenericInt'.


So how should I correct the XSD code?


No comments:

Post a Comment