[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: HELP: XML-Schema - Array and Type Choice?
Eddie Robertsson <eddie@a...> 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@c... URL: http://www.ltg.ed.ac.uk/~ht/
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|