Selector Clarification

Hi,

I have two small schemas for an instance file defining Id/y constraints. One 
works and the other does not. I doubt the other one is invalid.

schema1: This works

<xsd:element name="root">
  <xsd:complexType>
    <xsd:sequence>
      <xsd:element name="Book" maxOccurs="unbounded">
        <xsd:complexType>
          <xsd:sequence>
            <xsd:element name="isbn" type="xsd:string"/>
          </xsd:sequence>
          <xsd:attribute name="name" type="xsd:string" use="required"/>
        </xsd:complexType>
      </xsd:element>
    </xsd:sequence>
  </xsd:complexType>
  
  <xsd:key name="BookKey">
    <xsd:selector xpath="./Book"/>
    <xsd:field xpath="isbn"/>
  </xsd:key>
  
</xsd:element>


schema2: This does not works

<xsd:element name="root">
  <xsd:complexType>
    <xsd:sequence>
      <xsd:element name="Book" maxOccurs="unbounded">
        <xsd:complexType>
          <xsd:sequence>
            <xsd:element name="isbn" type="xsd:string"/>
          </xsd:sequence>
          <xsd:attribute name="name" type="xsd:string" use="required"/>
        </xsd:complexType>
        
        <xsd:key name="BookKey">
          <xsd:selector xpath="."/>
          <xsd:field xpath="isbn"/>
        </xsd:key>
        
      </xsd:element>
    </xsd:sequence>
  </xsd:complexType>
</xsd:element>

The spec says:
http://www.w3.org/TR/xmlschema-1/#Identity-constraint_Definition_details
[[
{selector} specifies a restricted XPath ([XPath]) expression relative to 
instances of the element being declared. This must identify a node set of 
subordinate elements (i.e. contained within the declared element) to which the 
constraint applies.
]]
but, there could be something that I have missed.

Can somebody clarify on this.

Cheers,
Rahul.

Sun Microsystems, Inc.

Received on Monday, 8 April 2002 04:22:55 UTC