How to define an Xpath selector in an xml schema for a recursive type

Edit: added keys.

Hi,

I have an 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 an XPath selector to declare keyref for the ref attribute, but I have no hint on 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> 

Thank you for your time.

+4
source share
1 answer

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

See the specification for more information: http://www.w3.org/TR/xmlschema-1/#c-selector-xpath

The <xsd:selector> element contains an XML Path Language (XPath) expression that defines a set of elements for which the values ​​specified in the field must be unique, so it should not refer to the ref attribute. The <xsd:field> elements refer to values ​​that must be unique within this set, so for the ref attributes (and the rest of the fields for other values ​​if you need to have a unique combination of values).

+11
source

All Articles