Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Identity constraints problem

From: "Joe Halpin" <jhalpin100@-----.--->
To: "Michael Kay" <mike@--------.--->
Date: 11/12/2008 8:18:00 PM
Doh!!

Thanks, I was overthinking it.

Joe

On Wed, Nov 12, 2008 at 2:01 PM, Michael Kay <mike@s...> wrote:
> If the constraint applies within a branch, define the <xs:unique> constraint
> at the level of the branch:
>
>>     <xs:complexType name="Branch">
>>         <xs:sequence>
>>             <xs:element name="unique-element" type="UniqueElement" />
>>         </xs:sequence>
>>         <xs:attribute name="id" type="xs:nonNegativeInteger" />
>>         <xs:unique name="ElementKey">
>>             <xs:selector xpath="unique-element" />
>>             <xs:field xpath="@id" />
>>         </xs:unique>
>>     </xs:complexType>
>
> Michael Kay
> http://www.saxonica.com/
>
>> -----Original Message-----
>> From: xmlschema-dev-request@w...
>> [mailto:xmlschema-dev-request@w...] On Behalf Of Joe Halpin
>> Sent: 12 November 2008 19:49
>> To: xmlschema-dev@w...
>> Subject: 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
>>
>
>



transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent