[XMLSCHEMA-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Identity constraints problem

From: Joe Halpin <jhalpin100@gmail.com>
Date: Wed, 12 Nov 2008 13:49:15 -0600
Message-ID: <4dc28b160811121149pf73b7efxb9bac666506fcabd@mail.gmail.com>
To: xmlschema-dev@w3.org
Identity constraints problem

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 GMT

Subscribe to the Stylus Scoop newsletter for helpful XML tips and tutorials.
Email
First Name
Last Name
Company

Download Stylus Studio 6 XML Enterprise Edition

Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.