OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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



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