- From: Joe Halpin <jhalpin100@gmail.com>
- Date: Wed, 12 Nov 2008 13:49:15 -0600
- To: xmlschema-dev@w3.org
I'm trying to figure out how to use identity constraints that are limited to a single branch of an xml document. For example, given the following xml: <?xml version="1.0"?> <base xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="test.xsd"> <branch id="1"> <unique-element id="1"> <unique-child id="2" /> </unique-element> <unique-element id="3"> <unique-child id="4" /> </unique-element> <unique-element id="5"> <unique-child id="6" /> </unique-element> </branch> <branch id="2"> <unique-element id="1"> <unique-child id="2" /> </unique-element> <unique-element id="3"> <unique-child id="4" /> </unique-element> </branch> </base> I'd like to ensure that unique-element and unique-child id are unique within the branch in which they appear, but only within that context. As it is, I keep getting identity constraint errors because the ids are duplicated between branches. What I'm doing is pretty much like this: <?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="base" type="Base"> <xs:unique name="BranchKey"> <xs:selector xpath="branch" /> <xs:field xpath="@id" /> </xs:unique> <xs:unique name="ElementKey"> <xs:selector xpath="branch/unique-element" /> <xs:field xpath="@id" /> </xs:unique> <xs:unique name="ChildKey"> <xs:selector xpath="branch/unique-element/unique-child" /> <xs:field xpath="@id" /> </xs:unique> </xs:element> <xs:complexType name="Base"> <xs:sequence> <xs:element name="branch" type="Branch" maxOccurs="unbounded" /> </xs:sequence> </xs:complexType> <xs:complexType name="Branch"> <xs:sequence> <xs:element name="unique-element" type="UniqueElement" /> </xs:sequence> <xs:attribute name="id" type="xs:nonNegativeInteger" /> </xs:complexType> <xs:complexType name="UniqueElement"> <xs:sequence> <xs:element name="unique-child" maxOccurs="unbounded"> <xs:complexType> <xs:attribute name="id" type="xs:nonNegativeInteger" /> </xs:complexType> </xs:element> </xs:sequence> <xs:attribute name="id" type="xs:nonNegativeInteger" /> </xs:complexType> </xs:schema> I'm probably just missing it. I've been looking at this so long I suspect I can't see it any more. Is there a way to do what I want? Thanks joe
Received on Wednesday, 12 November 2008 19:49:51 UTC