W3C home > Mailing lists > Public > xmlschema-dev@w3.org > April 2001

Re: [Moderator Action] Array and Type Choice?

From: Henry S. Thompson <ht@cogsci.ed.ac.uk>
Date: 12 Apr 2001 19:00:46 +0100
To: Risheng Lin <rlin@eng.utoledo.edu>
Cc: xmlschema-dev@w3.org
Message-ID: <f5bzodm80c1.fsf@cogsci.ed.ac.uk>
Risheng Lin <rlin@eng.utoledo.edu> writes:

> Dear member,
> 
> I have 2 more questions:
> 
> 1. Is there any way to represent an array?
> 
> e.g. for String title[numberOfTitle], where number of title is not
> known as a priori when schema author developed it. The numberofTitle
> is of type xsd:integer designed in schema, and the value will be
> given in an xml document instance by user, but when the user
> supplies this data, schema must validate that the maxOccurs can only
> be numberOfTitle data items.

No runtime constraints like this are supported in XML Schema 1.0, sorry.

> How to design such an schema? And what is the best practice? In such a
> situation, do I have to resort to XPATH?

That would work, yes.

> 2. Is there any way to design a schema such that given the following 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>
> 
> 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? Do I have to use XSLT?

No, but you can do something similar using xsi:type, see the Primer [1].

ht

[1] http://www.w3.org/TR/xmlschema-0/
-- 
  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/
Received on Thursday, 12 April 2001 14:00:48 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 11 January 2011 00:14:20 GMT