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

RE: Defining uniqueness on optional element

From: Cams Ismael <Ismael.Cams@siemens.com>
Date: Thu, 27 Mar 2003 13:34:24 +0100
Message-ID: <57FD2C3A246F76438CA6FDAD8FE9F1957ABC73@hrtades7.atea.be>
To: "'ht@cogsci.ed.ac.uk'" <ht@cogsci.ed.ac.uk>
Cc: "'xmlschema-dev@w3.org'" <xmlschema-dev@w3.org>

> There's no way to write identity constraints which make this OK but
> rule out the obvious bad cases.  The problem is not that it's an
> _error_ for a field of a unique constraint to be missing, it's just
> that if a field _is_ missing then the selected element is not
> considered at all.  So in the above example, a two-part unique on
> 'root' which selects 'mayHaveDaughter' with fields '@f1' and 'd' will
> not constrain empty 'mayHaveDaughter' elements at all.

I have tested the following:

xsd file:

<?xml version="1.0"?>

<xsd:schema xmlns:ipm="http://unique/test"
<xsd:element name="root">
			<xsd:element ref="ipm:mayHaveDaughter" minOccurs="0"
	<xsd:unique name="uniqueNode">
		<xsd:selector xpath="ipm:mayHaveDaughter"/>
		<xsd:field xpath="@f1"/>
		<xsd:field xpath="ipm:d"/>

<xsd:element name="mayHaveDaughter">
			<xsd:element name="d" minOccurs="0" maxOccurs="1"
		<xsd:attribute name="f1" type="xsd:string"/>


example file 1:
<?xml version="1.0"?>

<root xmlns="http://unique/test" 
	  xsi:schemaLocation="http://unique/test unique.xsd">
 <mayHaveDaughter f1="a"/>
 <mayHaveDaughter f1="b"/>
 <mayHaveDaughter f1="c"/>
 <mayHaveDaughter f1="c"/>

Both MSXML4.0 and xsdvalid give an error that indicate 'c' as duplicate key.
So if indeed all the <mayHaveDaughter> elements that have no <d> element are
ignored, no error should be generated in this case. Or am I wrong with that
? In case of Xerces I get an error message: '[Error] unique.xml:7:27: Not
enough values specified for <unique> identity constraint specified for
element "root" ' In neither cases this is a valid error. 
I have tried some other combinations and to me it seems like the parsers
behave as following:
	* When one of the fields is not available there is still be checked
on the other fields

I have tried to find this back in the recs, but I didn't succeed in it.

Am I missing something here ?

Received on Thursday, 27 March 2003 07:34:31 UTC

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