Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


XML Schema co-occurrence constraint workaround

From: "Andrew Welch" <andrew.j.welch@-----.--->
To: "xml-dev@-----.---.--- ----------" <-------@-----.---.--->
Date: 6/17/2008 8:26:00 AM
Here's a potential workaround for the co-constraint problem in XML Schema.

Given some XML:

<elem type="typeA">
  <typeA/>
</elem>

<elem type="typeB">
  <typeB/>
</elem>

...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">
  <typeA/>
</elem>

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

with suitable type definitions in the schema:

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

<xs:complexType name="elem_typeB">
  <xs:sequence>
    <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
http://andrewjwelch.com
Kernow: http://kernowforsaxon.sf.net/


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent