[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: Eddie Robertsson <eddie@a...>
  • To: Risheng Lin <rlin@e...>
  • Date: Tue, 12 Jun 2001 11:29:48 +1000

xsd array
Hi,

Risheng Lin wrote:

1. Is there any way to represent an array?

I know that the schema recommendation does not support this yet. But I want to find a best solution for this if possible. For example, my code has a variable:

   String title[numberOfTitle], where numberOfTitle is not known as a priori when schema author developed it. The numberofTitle is of type xsd:integer designed in schema, and its value will be given by user in an xml document instance, but when the user supplies this data, schema must validate that the maxOccurs can only be numberOfTitle data items.

How to design such an schema? In such a situation, do I have to resort to XPATH?

You can't specify these kinds of constraints with W3C XML Schema. However, Schematron is very good at this an can easily be integrated with XML Schema. See http://www.xfront.com/ExtendingSchemas.html for more details.
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]:

"The order in which the ·memberTypes· are specified in the definition (that is, the order of the <simpleType> children of the <union> element, or the order of the QNames in the memberTypes attribute) is significant. During validation, an element or attribute's value is validated against the ·memberTypes· in the order in which they appear in the definition until a match is found. The evaluation order can be overridden with the use of xsi:type."

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?

Cheers,
/Eddie

[1] http://www.w3.org/TR/xmlschema-2/#union-datatypes
 


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-2007 All Rights Reserved.