Re: XML Schema Design Issue.

Kartik Babu <babuk@cs.rpi.edu> writes:

> Is it currently possible to do this with XML Schema
> I have the following dtd:
> <!ELEMENT person (name,pid,sex,(parent,parent?)?,child*) >
> <!ElEMENT parent (#PCDATA)>
> <!ATTRIBUTE parent role CDATA #REQUIRED>
>
> now my question is that the role must either mother or father, which is
> easy to do. But, under the current XML specification, can I, without any
> changes to the given DTD make it such that a particular person cannot
> accidentally have two mothers or two fathers. How can I enforce that if a
> person has two parents listed only one can be role=mother and only one can
> be role=father ?

W3C XML Schema doesn't provide co-constraints, that is, some form of
equational logic relating the values of attributes and elements.
However, your particular problem can be solved by defining 'role' as a
key for 'parent' elements within 'person' elements, thereby requiring
them not to have the same value:

 <xs:element name="person">
  <xs:complexType>
   <xs:sequence>
    . . .
   </xs:sequence>
  </xs:complexType>

  <xs:key name="forceHetero">
   <xs:selector xpath="parent"/>
   <xs:field xpath="@role"/>
  </xs:key>

 </xs:element>

ht
-- 
  Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh
                      Half-time member of W3C Team
     2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440
	    Fax: (44) 131 650-4587, e-mail: ht@cogsci.ed.ac.uk
		     URL: http://www.ltg.ed.ac.uk/~ht/
 [mail really from me _always_ has this .sig -- mail without it is forged spam]

Received on Monday, 27 October 2003 05:28:21 UTC