Re: An element with more than one possible type

Hi,

pau carre <pau.carre@gmail.com> writes:

> <items>
> <item name = "pen" color ="22">
> <item name = "pencil" smoothness = "10" >
> </items>
>
> It is to say, if name is "pen" , then use the "color" attribute.
> When name is "pencil" then use "smoothness" attribute.

You won't be able to do this in XML Schema. The closest you can
get is with xsi:type-based dynamic typing, e.g.,

<items>
  <item xsi:type="pen" color ="22"/>
  <item xsi:type="pencil" smoothness = "10"/>
</items>

To achieve this you would define a base type for item and then
extend it to "pen" and "pencil".

If I were you, I would just get rid of the extra naming layer and
simply have something like this:

<items>
  <pen color ="22"/>
  <pencil smoothness = "10"/>
</items>

You can still keep this design open-ended (i.e., you can add more
item types without modifying the items definition) with substitution
groups.


hth,
-boris


-- 
Boris Kolpackov
Code Synthesis Tools CC
http://www.codesynthesis.com
Open-Source, Cross-Platform C++ XML Data Binding

Received on Saturday, 3 February 2007 07:59:13 UTC