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

RE: Sequence of elements of same name but various types

From: Michael Kay <mike@saxonica.com>
Date: Wed, 14 Apr 2010 14:39:48 +0100
To: <allamistakeo18@mac.com>, <xmlschema-dev@w3.org>
Message-ID: <85FE828BC901422B9C884577241E3A2F@Sealion>
> I am trying to write an XSD file for an existing XML-based 
> file format. The format represents a list of elements, each 
> element being either in the following format: 
> 
> <item flavor="text">
> 	some text
> </item>
> 
> or in the following format: 
> 
> <item flavor="elements">
> 	<elem />
> </item>
> 
> In other words, all elements are named "item", but their 
> allowed content depends on the value of the attribute 
> "flavor". If flavor="text", the content must be text that 
> satisfies some regular expression, and if flavor="elements", 
> the content must be an element named "elem". 
> 
> Is there a way to write an XSD file for this format? Or is it 
> just not possible because of the Unique Particle Attribution 
> constraint? 

It's not possible in XSD 1.0 (for various reasons including the Element
Declarations Consistent constraint). It's possible in XSD 1.1 using
Conditional Type Assignment, where the type assigned to the element depends
on a function of the attribute values.

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay 
Received on Wednesday, 14 April 2010 13:40:19 GMT

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