XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
Can't get simple key constraint to work

Hi,

I'm a newbie to XML schema design and am having trouble getting what would 
seem
to be a painfully simple key constraint to work. I've looked at tutorial 
pages
on the creation of keys and use of Xpath therein and still no joy.

Here is the stripped down schema, with my futile attempt at a key constraint
named "OuterNameKey":

 <?xml version="1.0" encoding="UTF-8" ?>
 <xsd:schema targetNamespace="http://TBD-URI"; elementFormDefault="qualified"
  attributeFormDefault="unqualified" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema";
  xmlns="http://TBD-URI";>

  <xsd:element name="MyRoot" type="MyRootType">
     <xsd:key name="OuterNameKey">
        <xsd:selector xpath="./Outer"/>
        <xsd:field xpath="@OuterName"/>
     </xsd:key>
  </xsd:element>

  <xsd:complexType name="MyRootType">
    <xsd:sequence>
       <xsd:element name="Outer" type="OuterType" maxOccurs="unbounded"/>
    </xsd:sequence>
  </xsd:complexType>

  <xsd:complexType name="OuterType">
     <xsd:attribute name="OuterName" type="xsd:string" use="required"/>
  </xsd:complexType>
 </xsd:schema>

I want the OuterNameKey key constraint to say, "The value of the OuterName
attribute of the <Outer> element must be unique within the enclosing 
<MyRoot>
element.".

Here is a test XML file that (as far as I can understand the Xpath / XML key
tutorials I've seen) should *not* validate because a duplicate value for
OuterName has been used in two <Outer> elements:

 <?xml version="1.0" encoding="UTF-8"?>
 <MyRoot xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
     xsi:schemaLocation="http://TBD-URI Example.xsd" xmlns="http://TBD-URI";>
     <Outer OuterName="Must Be Unique"/>
     <Outer OuterName="Must Be Unique"/>
 </MyRoot>

I'm using Oxygen and when I hit validate for the above XML it validates.

Now I *was* able to get the following version of the "OuterNameKey" key
constraint to catch the error in the XML above. I changed the xpath in
xsd:selector to "*", that is:

   <xsd:key name="OuterNameKey">
      <xsd:selector xpath="*"/>
      <xsd:field xpath="@OuterName"/>
   </xsd:key>

If the change above is made to the schema then the example XML will not
validate. Oxygen will say:

 Duplicate key value [Must Be Unique] declared for identity constraint
 "OuterNameKey" of element "MyRoot".

which is what I want, except I don't want to use this wildcard hack.

So what am I missing? 



[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS