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

Re: Custom discriminators

From: G. Ken Holman <gkholman@CraneSoftwrights.com>
Date: Sun, 18 Dec 2005 08:04:48 -0500
Message-Id: <6.2.3.4.2.20051218075208.05056ce0@pop.storm.ca>
To: <xmlschema-dev@w3.org>

At 2005-12-18 12:07 +0100, Gregor Zeitlinger wrote:
>I was wondering if it is possible to define custom discriminators.
>...
>So I have type="(date|time)". If type="date" there are addional 
>attributes available.
>
>In another situation, there is an element with two discriminator attributes:
>type="(|password)" and multiline="(true|false)".
>I want to assign four different Schema types based on the 
>combinations of those attributes.

You've described the need for co-occurrence constraints and 
co-occurrence constraints are not supported in W3C Schema 1.0.

Such constraints can be expressed in ISO/IEC 19757-2 RELAX-NG 
(example below, I guessed a value for your "type" attribute since 
your example above seems incomplete) and I gather from posts on this 
list that the W3C committee has long been considering how such 
constraints can be introduced into W3C Schema.  RELAX-NG treats both 
attributes and elements as first-class constructs in the content 
model operators.

RELAX-NG is part 2 of Document Schema Definition Languages (DSDL) and 
I gather what is not well known is that the objective of DSDL is to 
be inclusive to be able to incorporate any validation technology by 
reference (including W3C Schema) so that technologies both inside and 
outside of DSDL can be expressed as part of a validation suite.

I hope this helps.

. . . . . . . . . Ken

T:\>type gregor.rnc
datatypes xsd = "http://www.w3.org/2001/XMLSchema-datatypes"

# test for Gregor

start = element tests { test+ }

test = element test
    {
       (
          attribute type { "abc" },
          attribute multiline { "true" },
          xsd:positiveInteger
       )
       |
       (
          attribute type { "abc" },
          attribute multiline { "false" },
          xsd:string
       )
       |
       (
          attribute type { "password" },
          attribute multiline { "true" },
          xsd:float
       )
       |
       (
          attribute type { "password" },
          attribute multiline { "false" },
          xsd:integer
       )
    }

# end of file

T:\>type gregor.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<tests>
   <!--good-->
   <test type="abc" multiline="false">hello</test>
   <test type="abc" multiline="true">123</test>
   <test type="password" multiline="false">456</test>
   <test type="password" multiline="true">456.78</test>
   <!--bad-->
   <test type="password" multiline="false">456.78</test>
   <test type="abc" multiline="true">hello</test>
   <test type="abc" multiline="true">-123</test>
</tests>
T:\>jing -c gregor.rnc gregor.xml
T:\gregor.xml:9: error: bad character content for element
T:\gregor.xml:10: error: bad character content for element
T:\gregor.xml:11: error: bad character content for element

T:\>

--
Upcoming XSLT/XSL-FO hands-on courses:  Denver,CO March 13-17,2006
World-wide on-site corporate, govt. & user group XML/XSL training.
G. Ken Holman                 mailto:gkholman@CraneSoftwrights.com
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/x/
Box 266, Kars, Ontario CANADA K0A-2E0    +1(613)489-0999 (F:-0995)
Male Cancer Awareness Aug'05  http://www.CraneSoftwrights.com/x/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal
Received on Sunday, 18 December 2005 13:09:27 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 11 January 2011 00:14:51 GMT