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

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Re: [xml-dev] Schema Question

[ Lists Home | Date Index | Thread Index ]


Dan White writes:
> I have a situation where the incoming XML will have an element/attribute
> specifying one of four enumerated choices.  Depending on the value of that
> choice, the elements that follow will be different.
> 
> Like this:
> <foo>
>   <mode>one</mode>
>   <data1>aaa</data1>
>   <data2>bbb</data2>
> </foo
> 
> <foo>
>   <mode>two</mode>
>   <data3>ccc</data3>
>   <data4>ddd</data4>
> </foo>
> 
> or
> <foo mode="one">
>   <data1>aaa</data1>
>   <data2>bbb</data2>
> </foo
> 
> <foo mode="two">
>   <data3>ccc</data3>
>   <data4>ddd</data4>
> </foo>
> 
> How does one set up the schema to validate the appropriate sequence of
> elements based on the value of the "controlling" element/attribute ?

If you are committed to the particular attribute names or the use of elements,
then you cannot do this with XML Schema. You could layer Schematron or
something similar on top of it.

If you use xsi:type as your attribute, you can get the effect of this by
defining a type for each of the variants and using the name of that type as the
value of the xsi:type attribute. The types will all have to derive from a
common base, but that base can be nothing, and they can all extend from it.

Or, you can use different element names for the different variants, drop the
extra attribute and use substitution groups, e.g.

<one>
  <data1>aaa</data1>
  <data2>bbb</data2>
</one>
 
<two>
  <data3>ccc</data3>
  <data4>ddd</data4>
</two>

The deal with substitution groups is that you don't have to put a big explicit
choice into the element that uses these, but just ref the root of the
substitution group.

See http://www.mathling.com/xsd/ for gory details and extended examples.

	-- Mary
	   Holstege@mathling.com






 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS