Altova Mailing List Archives


Re: Question about uniqueness

From: Eddie Robertsson <erobertsson@-------.---.-->
To: odwl <odwl@---.--->
Date: 9/11/2002 8:05:00 PM
Hi,

> <?xml version="1.0" encoding="ISO-8859-1"?>
> <Site xmlns="http://n-side/site/ssShema"
>             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>           xsi:schemaLocation="http://n-side/site/ssShema 
> ../schema/ssSchema.xsd">
> <Home name="CorHome">
>         <Topic name="Your_Needs">
>             <View name="Choice_1"/>
>             <View name="CorHome"/>
>             <View name="Your_Needs2"/>
>         </Topic>
>         <Topic name="Your_Needs2">
>             <View name="Choice_3"/>
>             <View name="Choice_4"/>
>             <View name="Choice_3"/>
>         </Topic>
>         <Topic name="Your_Needs"/>
>     </Home>
>     </Site>
>
> I would like to have a schema that enforces the uniqueness of all the 
> "name" attributes (for Home, Topic and View elements). The above 
> document is thus not valid (at all).
>
> I inserted the following XML Schema fragment within the Site element 
> definition:
>
>         <unique name="idName">       
>             <selector xpath=".//*"/>
>             <field xpath="@name"/>
>         </unique>
>
> But it is not working : there is no validation error for the above 
> document. 

What validator are you using?
The above look perfectly fine with me and validates with XMLSpy">XMLSpy 4.4 and 
MSXML4. I tried this with Xerces 2.0.1 but it didn't pick up on the 
error so that's a bug. I haven't tried with the latest 2.1.0 so 
hopefully this is fixed in the new version.

> Note that with the following fragment, it's OK, I have an error 
> because of "Choice_3" appearing twice.
>
>         <unique name="idName">       
>             <selector xpath=".//View"/>
>             <field xpath="@name"/>
>         </unique>
>
> and I have the uniqueness of the name in all the View pages

I am, however, very surprised that you got the above to work. Note that 
your instance document use a default namespace which means that all you 
elements are declared in the "http://n-side/site/ssShema" namespace. 
Since XPath doesn't support the default namespace the above uniqueness 
check would never match any elements and should never give you an error. 
For this to work you must explicitly declare a namespace prefix for 
the "http://n-side/site/ssShema" namespace in your schema document and 
use that in the XPath expression:

<xs:schema ... xmlns:s="http://n-side/site/ssShema" ...>
....
        <unique name="idName">       
            <selector xpath=".//s:View"/>
            <field xpath="@name"/>
        </unique>
...
</xs:schema>

Cheers,
/Eddie


From xmlschema-dev-request@t... Tue Sep 10 22:35:29 2002
Received: from tux.w3.org (tux.w3.or

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.