W3C home > Mailing lists > Public > xmlschema-dev@w3.org > December 2003

Re: attemting to create a mutli-type element

From: Jeni Tennison <jeni@jenitennison.com>
Date: Thu, 4 Dec 2003 10:46:03 +0000
Message-ID: <131-835177171.20031204104603@jenitennison.com>
To: "London ." <epsilonknot@hotmail.com>
Cc: xmlschema-dev@w3.org

Hi London,

> this works fine, but what i would like to do is have an xsd that
> could be used to validate this:
> <data>
>   <value dt="int">1</value>
>   <value dt="string">hello</value>
> </data>
> im at a complete loss here, any help would be appreciated.

This is known as a co-occurrence constraint; XML Schema does not have
good support for co-occurrence constraints. If you're willing to
change your vocabulary slightly, however, XML Schema automatically
supports the use of the xsi:type attribute to indicate the type of the
value of an element. Something like:

<data xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  <value xsi:type="xs:int">1</value>
  <value xsi:type="xs:string">hello</value>

will work with a schema like:

<xs:element name="data">
      <xs:element name="value" type="xs:anyType"
                  minOccurs="0" maxOccurs="unbounded" />

Otherwise, you need to use Schematron or RELAX NG to enforce the rule
that the value of the <value> element must be of the type specified by
the dt attribute.



Jeni Tennison
Received on Thursday, 4 December 2003 05:48:32 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 23:15:17 UTC