/Con/:
Hi, thanks to responding to my post. Anyway, if type tag is of the
following:
short
int
long int
float
double
How does enforce the type of value in the value tag?
Define a base type for your "mytype" element, like:
<xs:complexTy pe name="MyType">
<xs:sequence>
<xs:element name="name" type="xs:string " />
<xs:element name="type" type="ValueType s" />
<xs:element name="value" type"xs:anySimp leType" />
</xs:sequence>
</xs:complexType>
<xs:element name="mytype" type="MyType" />
Define the "ValueTypes ":
<xs:simpleTyp e name="ValueType s">
<xs:restricti on base="xs:string ">
<xs:enumerati on value="short" />
<xs:enumerati on value="int" />
<xs:enumerati on value="long int" />
<xs:enumerati on value="float" />
<xs:enumerati on value="double" />
</xs:restriction>
</xs:simpleType>
Define the derived types:
<xs:complexTy pe name="MyShortTy pe">
<xs:complexCont ent>
<xs:restricti on base="MyType">
<xs:sequence>
<xs:element name="name" type="xs:string " />
<xs:element name="type" type="ValueType s" fixed="short" />
<xs:element name="value" type"xs:short" />
</xs:sequence>
</xs:restriction>
<xs:complexCont ent>
</xs:complexType>
<!-- and so on -->
Then use the xsi:type attribute in the instance document:
<mytype>
<name>value2</name>
<type>int</type>
<value>ivalid still valid</value>
</mytype>
<mytype xsi:type="MySho rtType">
<name>value3</name>
<type>short</type>
<value>123</value>
</mytype>
I haven't tried it but I think it should work. :-) Similar example
<http://www.w3.org/TR/xmlschema-0/#abstract> is given in the "XML
Schema Part 0: Primer", although it forces the usage of the xsi:type
attribute, declaring the base type abstract.
--
Stanimir