views:

46

answers:

1

Edit: added keys.

Hi,

I have a xml schema with the following types:

<xs:complexType name="definition">
  <xs:sequence/>
  <xs:attribute name="id"/>
</xs:complexType>

<xsd:key name="definitionId">
  <xsd:selector xpath="definition"/>
  <xsd:field xpath="@id"/>
</xsd:key>

<xs:complexType name="elem">
  <xs:sequence>
    <xs:element name="entry1" type="elem" minOccurs="0" maxOccurs="unbounded"/>
    <xs:element name="entry2" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
  </xs:sequence>
  <xs:attribute name="ref" type="xs:string" use="required"/>
</xs:complexType>

This allows something like:

<definition id="A">
<definition id="B">
<definition id="C">

<entry1 ref="A">
  <entry1 ref="B">
    <entry1 ref="C"/>
    <entry2/>
  </entry1>
  <entry1 ref="C">
  </entry1>
</entry1>

I need a a XPath-selector to declare a keyref to the ref attribute but i don't have a clue how to define a recursive path.

<xsd:keyref name="definitionRef" refer="definitionId">
  <xsd:selector xpath="???"/>  <<<how to find all "ref" of entry1 ?    
  <xsd:field xpath="@ref"/>
</xsd:keyref>

Thanks for your time.

+1  A: 

<xsd:selector> supports restricted XPath expressions. Only child axis is allowed but the XPath expression can begin with .// so you can use a recursive expression .//entry1

For more detailed info, see the specification: http://www.w3.org/TR/xmlschema-1/#c-selector-xpath

The <xsd:selector> element contains an XML Path Language (XPath) expression specifying the set of elements across which the values specified by field must be unique so it shouldn't refer to attribute ref. <xsd:field> element(s) refer to the values that should be unique within that set so it should refer to attribute ref (and rest of the fields to other values, if you need to have an unique combination of values).

jasso
Thank you very much. I tried this for some time before my Question but missed the leading ".". Thanks for your help
kasten