[XMLSCHEMA-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

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
create dt element

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

will work with a schema like:

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

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.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/
Received on Thursday, 4 December 2003 05:48:32 GMT

Subscribe to the Stylus Scoop newsletter for helpful XML tips and tutorials.
Email
First Name
Last Name
Company

Download Stylus Studio 6 XML Enterprise Edition

Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.