Re: [Moderator Action] Anonymous Types with same name problem

John Britton <johnb@peakaudio.com> writes:

> I've run into a problem in attempting to define a schema for the following
> sample XML instance document:
> 
> <Settings>
>   <setting name="Number of FooDaddies" value="3"/>
>   <setting name="FooDaddies are In the House" value="true"/>
> </Settings>
> 
> The name values may contain white space, and thus aren't suitable as element
> names. The value of the value attributes are different in each setting
> element - i.e. I'm using anonymous type definitions to allow elements having
> the same name to have different content.

XML Schema specifically dis-allows this [1] -- the basic reasoning being
that the element<->type association should be stable within a
particular complex type.

If you really don't want to use different element names, define an
abstract type, use it <setting>, derive specialised types from it and
use xsi:type to signal which one you're using, e.g.

<element name="setting" type="my:stype"/>
<complexType name="stype">
 <attribute name="name" type="token"/>
 <attribute name="value"/>
</complexType>

<complexType name="s-int">
 <complexContent>
  <restriction base="my:stype">
   <attribute name="value" type="integer"/>
  </restriction
 </complexContent>
</complexType>

<complexType name="s-bool">
 <complexContent>
  <restriction base="my:stype">
   <attribute name="value" type="boolean"/>
  </restriction
 </complexContent>
</complexType>

 <Settings>
   <setting name="Number of FooDaddies" xsi:type="s-int" value="3"/>
   <setting name="FooDaddies are In the House" xsi:type="s-bool" value="true"/>
 </Settings>

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@cogsci.ed.ac.uk
		     URL: http://www.ltg.ed.ac.uk/~ht/

Received on Friday, 2 February 2001 07:22:16 UTC