[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: HELP: XML-Schema - Array and Type Choice?
- From: ht@cogsci.ed.ac.uk (Henry S. Thompson)
- To: Eddie Robertsson <eddie@allette.com.au>
- Date: Tue, 12 Jun 2001 13:28:50 +0100
Eddie Robertsson <eddie@allette.com.au> writes:
> Hi,
>
> Risheng Lin wrote:
<snip/>
> > 2. My second question is about type choice. Below is part of my
> > schema:
> >
> > <xsd:element name="DataValue">
> > <!-- data can be either float or double-->
> > <xsd:complexType>
> > <xsd:choice>
> > <xsd:element name="Data" type="xsd:float"
> > minOccurs="1" maxOccurs="unbounded"/>
> > <xsd:element name="Data" type="xsd:double" minOccurs="1"
> > maxOccurs="unbounded"/>
> > </xsd:choice>
> > <xsd:attribute ref="dataType" use="required" />
> > </xsd:complexType>
> > </xsd:element>
> >
> > But I want more constraints on this schema --- when user supplies the
> > attribute dataType to be "float", the schema will only allow the
> > instance document to supply Data Element to be of type xsd:float; on
> > the other hand, if attribute dataType is "double", the XML document
> > can only supply Data Element of type xsd:double?
>
> I'm not sure this will work but you can try to create your own datatype
> that is a union between float and double like this:
>
> <xsd:simpleType name="float_double">
> <xsd:union memberTypes="xsd:float xsd:double"/>
> </xsd:simpleType>
>
> Then declare your element Data to be of this type:
>
> <xsd:element name="Data" type="float_double" minOccurs="1"
> maxOccurs="unbounded"/>
>
> In your instance document you can then use the xsi:type attribute to
> specify which type you use:
>
> ...
> <Data xsi:type="xsd:double">_floatvalue_</Data>
> ...
>
> However, I'm not sure this will work. The spec says [1]:
<snip/>
It should work.
> I'm not sure if you can just override the evaluation order or if you can
> actually specify the specific type within the union. I.e will the
> validator continue to check the the above example for conformance to the
> xsd:float type if the xsd:double check fails?
> [1] http://www.w3.org/TR/xmlschema-2/#union-datatypes
The spec. should be clearer here -- xsi:type _completely_ overrides
the union--if it's not a double, it's an error, in the above example.
ht
--
Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh
W3C Fellow 1999--2001, part-time member of W3C Team
2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440
Fax: (44) 131 650-4587, e-mail: ht@cogsci.ed.ac.uk
URL: http://www.ltg.ed.ac.uk/~ht/