Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Semi-unique IDs in Schema

From: Victor Engmark <victor.engmark@----.-->
To: NULL
Date: 5/3/2004 12:09:00 PM
Martin Honnen wrote:
> 
> 
> Victor Engmark wrote:
> 
>> How do I define that the contents of an element should be unique only 
>> in a sub-tree of the whole XML file?
>>
>> In my case, I have several documents, each containing several files. 
>> The file names have to be unique only within each document. I.e., the 
>> following is valid:
>> <doc>
>>     <file>AAA</file>
>>     <file>BBB</file>
>> </doc>
>> <doc>
>>     <file>AAA</file>
>> </doc>
>>
>> , while the following is not:
>> <doc>
>>     <file>AAA</file>
>>     <file>BBB</file>
>>     <file>AAA</file> <!-- Matches previous file! -->
>> </doc>
> 
> 
> XML schema allows for uniqueness constraints, here is an example schema
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
> 
> <xs:element name="root">
>   <xs:complexType>
>     <xs:sequence>
>       <xs:element ref="doc" maxOccurs="unbounded" />
>     </xs:sequence>
>   </xs:complexType>
> </xs:element>
> 
> <xs:element name="doc">
>   <xs:complexType>
>     <xs:sequence>
>       <xs:element name="file" type="xs:string" maxOccurs="unbounded" />
>     </xs:sequence>
>   </xs:complexType>
>   <xs:unique name="uniqueFile">
>     <xs:selector xpath="file" />
>     <xs:field xpath="." />
>   </xs:unique>
> </xs:element>
> 
> </xs:schema>
> 
> and an example document
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>       xsi:noNamespaceSchemaLocation="test20040430Xsd.xml">
>   <doc>
>       <file>AAA</file>
>       <file>BBB</file>
>   </doc>
>   <doc>
>       <file>AAA</file>
>       <file>AAA</file>
>   </doc>
> </root>
> 
> where the validation will flag an error for the second <file> element in 
> the second <doc> element.

I tried this, but I have obviously overlooked something, because the 
file http://vengmark.home.cern.ch/vengmark/moi/examples/input.xml is 
valid according to 
http://vengmark.home.cern.ch/vengmark/moi/examples/moi.xsd, even though 
none of the ID elements are unique. Sorry the example is verbose...

-- 
Victor


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