- From: Jeni Tennison <jeni@jenitennison.com>
- Date: Mon, 23 Aug 2004 17:15:10 +0100
- To: "Michael Kay" <mhk@mhk.me.uk>
- CC: "'Asleson, Ryan'" <asleson@BIWORLDWIDE.com>, xmlschema-dev@w3.org
Hi Mike, >> This is the most frequent of FAQs. It can't be done in XML Schema. > > Actually, I think someone did discover a way of doing it. You can > use a choice as in (2) below, and then use a uniqueness constraint > to ensure there is only one father and only one mother. Under the > element declaration for family, you add: > > <xs:unique name="one-father"> > <xs:selector xpath="."/> > <xs:field xpath="father"/> > </xs:unique> > > This will cause a validation error if a the xs:field expression > selects more than one node, that is, if a family has more than one > father. Yes, Eric van der Vlist came up with this in his XML Schema book. I was one of his technical editors, and I remember he was worried about whether it was legal. I thought that it was at the time, but (after the book came out) found something in the spec that made me question that. I think it was Clause 2.2 of Schema Component Constraint: Selector Value OK, which states: [The {selector}] must be an XPath expression involving the child axis whose abbreviated form is as given above. I think this means that the child axis must be used in the expression. In the above case, the selector "." does not involve the child axis, so I don't think it's legal. But it's extremely fuzzy, and I'm not sure whether the wording actually reflects the intention. Cheers, Jeni --- Jeni Tennison http://www.jenitennison.com/
Received on Monday, 23 August 2004 16:15:26 UTC