RE: Alternative versions of an element within one schema

Unfortunately there seems to be no way to do exactly what you want within
W3C XML Schemas as such - it is not a problem to allow <a> to hold different
kinds of content, but you can't make it depend on the attribute value.

A few workarounds were suggested on the list a short while ago, I believe
one of them involved using the xsi:type attribute on the <a> element to
specify what type you wanted, e.g.

<root xmlns:xsi=(schema instance namespace)>
	<a version="1.0" xsi:type="a_v1">
		...
	</a>
</root>

and

<root xmlns:xsi=(schema instance namespace)>
	<a version="2.0" xsi:type="a_v2">
		...
	</a>
</root>

and declaring the a_v1 and a_v2 complex types as appropriate, but of course
this does not make the instance document any prettier. All the other
workarounds require you to change the name of the element or use another
schema language.

Regards,

Steen

/**
 * Steen Lehmann - <mailto:slehmann@silverstream.com>
 * Senior Software Engineer (R&D), SilverStream Software 
 * <http://www.silverstream.com>
 */ 

> -----Original Message-----
> From: Paul B. Anderson [mailto:paul@pnlassociates.com]
> Sent: Thursday, March 07, 2002 12:08 AM
> To: xmlschema-dev@w3.org
> Subject: Alternative versions of an element within one schema
> 
> 
> Hi:
> 
> I'm trying to find a way to handle multiple versions of an element
> definition within a single schema.  I keep running into UPA problems
> (among others) so I was wondering if anyone has solved this problem.
> 
> I want to allow a single schema to validate instance documents like
> 
> <root>
>   <a version="1.0">
>     ... some complex content
>   </a>
> </root>
> 
> or
> 
> <root>
>   <a version="2.0">
>     ... complex content but different from version 1.0 in some way
>   </a>
> </root>
> 
> I have tried defining two groups, a10 and a20, that each have a fixed
> value of attribute version.  These are then listed in the schema under
> <root> within a choice element.
> 
> How can I make this work?  It seems as if it is an important 
> situation.
> 
> Thanks,
> 
> Paul
> 
> 

Received on Thursday, 7 March 2002 04:24:42 UTC