[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: HELP: XML-Schema - Array and Type Choice?

  • From: ht@c... (Henry S. Thompson)
  • To: Eddie Robertsson <eddie@a...>
  • Date: Tue, 12 Jun 2001 13:28:50 +0100

xsd array
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!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.