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


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
XML Schema co-occurrence constraint workaround

Here's a potential workaround for the co-constraint problem in XML Schema.

Given some XML:

<elem type="typeA">

<elem type="typeB">

...the problem is you can't constrain the contents of <elem> based on
the value of the type attribute.

You can do it though, if you add an xsi:type attribute to it to
explicitly set its type:

<elem type="typeA" xsi:type="elem_typeA">

<elem type="typeB" xsi:type="elem_typeB">

with suitable type definitions in the schema:

<xs:complexType name="elem_typeA">
    <xs:element ref="typeA"/>

<xs:complexType name="elem_typeB">
    <xs:element ref="typeB"/>

...and when the XML is validated the relevant definition will be used.

This technique is far from ideal as it involves modifying the source,
but only in a way which doesn't break it for anyone else. Given the
various options for validating co-constraints, this could well be the
most straightforward way (at least until 1.1 comes along).

(pasted from http://ajwelch.blogspot.com/2008/06/xml-schema-co-occurrence-constraint.html)

Andrew Welch
Kernow: http://kernowforsaxon.sf.net/

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]

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

Copyright 1993-2007 XML.org. This site is hosted by OASIS