W3C home > Mailing lists > Public > www-xml-schema-comments@w3.org > January to March 2004

Constraints, keys, and validation

From: etienne.lacazedieu <etienne.lacazedieu@laposte.net>
Date: 18 Mar 2004 08:19:59 -0700
Message-Id: <HUQCP5$A816EBBAC0E7CFB5464E43ED76F4394E@laposte.net>
To: "www-xml-schema-comments" <www-xml-schema-comments@w3.org>


I have a problem with some unicity constraints : I read in
Eric Van der Vlist's book, that you can use constraints to
check that an element has either an attribute, or an elment,
but bot both of them. I wanted to try to validate the fact
that it can have either an attribute a1, or an attribute a2,
but not both.

I made a little exemple, which follows : 

-------------- the schema ----------------------
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema elementFormDefault="qualified"

	<xsd:complexType name="Type">
			<xsd:element name="elt" type="xsd:string" minOccurs="0"
		<xsd:attribute name="foo" type="xsd:string"/>
		<xsd:attribute name="bar" type="xsd:string"/>
	<xsd:complexType name="Test">
			<xsd:element name="mustHaveFooOrElt" type="Type"
minOccurs="4" maxOccurs="4">
				<xsd:key name="eltOrfoo">
					<xsd:selector xpath="."/>
					<xsd:field xpath="@foo|ex:elt"/>
			<xsd:element name="mustHaveFooOrBar" type="Type"
maxOccurs="4" minOccurs="4">
				<xsd:key name="fooOrBar">
					<xsd:selector xpath="."/>
					<xsd:field xpath="@foo|@bar"/>
	<xsd:element name="test" type="Test"/>
----------------------------- the XML instance file 
<?xml version="1.0" encoding="UTF-8"?>
        <!--1 : Should be valid : the key is associated with a
single value eg: 'foo' -->
	<mustHaveFooOrElt foo="foo"/>
        <!-- 2 : Should be valid : the key is associated with
a single value eg: 'element' -->

        <!-- 3 : Should be invalid : the key is associated
with 2 values -->
	<mustHaveFooOrElt foo="foo">
        <!-- 4 : Should be invalid : the key is associated
with no value.-->
	<mustHaveFooOrElt bar="bar"/>
	<!-- 5 : Should be valid : the key is associated with a
single value eg: 'foo' -->
	<mustHaveFooOrBar foo="foo"/>
	<!-- 6 : Should be valid : the key is associated with a
single value eg: 'bar' -->
	<mustHaveFooOrBar bar="bar"/>
	<!-- 7 : Should be invalid : the key is associated with 2
	<mustHaveFooOrBar bar="bar" foo="foo"/>
	<!-- 8 : Should be invalid : the key is associated no value!-->

The comments reflects my understanding of the validation
process, as explained in the book I told about...My
interrogations come from the fact that a lot of parsers don't
give the same results for this exemple : 

- All the parsers don't validate the elements 4 and 8,
complaining that a key has no value, which is right,
- xerces (C or Java 2, last stable version available) does not
validate element 2, complaining that the key has no value,
whereas element 'elt' is defined. According to the book, it
should validate this content.
- xerces also validates elements 3 and 7, which should not be
valid, because there are two values for each key.

So, in fact, I really don't know what to think about all this,
but there are two possibilities : 

- Eric Van der Vlist is wrong, and Xerces is right...
- Xerces does not validate a valid XML content, and validates
some invalid content..

I'd really need to know who is right and who is wrong : I need
to write some schemas with such constraints, and I'd also like
to warn the one who's wrong!

Thanks for having read all this, and excuse my english mistakes!

Etienne Lacazedieu


Accédez au courrier électronique de La Poste : www.laposte.net ; 
3615 LAPOSTENET (0,34/mn) ; tél : 08 92 68 13 50 (0,34/mn)
Received on Thursday, 18 March 2004 10:23:08 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 14:50:02 UTC