XML technologies / XML Schema / XML Schema element reference / xs:field

(Excerpt from “XML Schema” by Eric van der Vlist)

Defining the field used for a uniqueness constraint.

<xs:field
    id = xs:ID
    xpath = xs:token
    {beliebige Attribute mit einem Nicht-Schema-Namensraum}
    >
    Content: (xs:annotation?)
</xs:field>

May occur within: xs:key, xs:keyref, xs:unique

Description

xs:field specifies the location of fields checked for a uniqueness constraint or reference to one.

Fields are elements or attributes identified by relative XPath expressions, namely xpath attributes, evaluated relative to the node selected by element xs:selector.

Composite keys can be expressed by defining several fields beneath an element xs:unique, xs:key or xs:keyref.

Restrictions

Attribute xpath uses a simple subset of XPath 1.0. The W3C XML Schema Working Group chose this to simplify processor implementation and keep paths within the current element’s scope.

This subset of XPath uses only the axes child, attribute, self and descendant-or-self in abbreviated form, with no tests in location steps or XPath functions. It is identical to the subset defined for xs:selector, except that attributes are allowed in xs:field but forbidden in xs:selector .

The formal extended BNF (Backus–Naur form) in the W3C recommendation is:

Field ::= Path ( ’|’ Path )* Path ::= (’.//’)? ( Step ’/’ )* ( Step | ’@’ NameTest ) Step ::= ’.’ | NameTest NameTest ::= QName | ’*’ | NCName ’:’ ’*’

For composite keys, node sets identified by each field must occur exactly once per locator iteration. With W3C XML Schema, for structures like the following:

<sect num="1">
    <sub-sect num="1"> Unterabschnitt 1.1 </sub-sect>
    <sub-sect num="2"> Unterabschnitt 1.2 </sub-sect>
</sect>
<sect num="1">
    <sub-sect num="3"> Unterabschnitt 1.3 </sub-sect>
    <sub-sect num="4"> Unterabschnitt 1.4 </sub-sect>
</sect>

this means multilevel composite keys cannot be defined over attributes num of sect and sub-sect. The locator would have to iterate over element sect, and attribute num of element sub-sect would then have several values per iteration.

Example

<xs:element name="library">
    <xs:complexType>
        .../...
    </xs:complexType>
    <xs:unique name="book">
        <xs:selector xpath="book"/>
        <xs:field xpath="isbn"/>
    </xs:unique>
</xs:element>

Attributes

id
Element ID according to W3C XML Schema.

xpath
Relative XPath expression identifying the field, or one of the fields, making up the key, key-reference or uniqueness constraint.

   

 

 

 

back to top