• +49-(0)721-402485-12
Ihre Experten für XML, XQuery und XML-Datenbanken

Node types

Any node is represented by node(). In addition, it is possible to demand a certain node type, as for example a text node or an element node. The type can be defined even more specific: For processing instructions a particular target can be demanded, for elements and attributes the name and/or the type, for documents a particular root element. The following table gives an overview of the different possibilities:

Node typeMeaning
node()any node
document-node()a document node
document-node(element(...))a document node where the document has
as root element an element of the indicated
type
text()a text node
comment()a comment node
processing-instruction()a processing instruction node
processing-instruction(Target)
processing-instruction("Target")
a processing instruction node
with the indicated target
element()
element(*)
element(*,*)
any element node
element(Name)a certain element
element(Name, Type) an element with a certain name and type
attribute()
attribute(*)
attribute(*,*)
any attribute
attribute(Name)a certain attribute
attribute(Name, Type)an attribute with a certain name and type

Table: List of different node types

The following image illustrates the relation of the respective indications for types of sequence items. From the left to the right the definition becomes more and more specific.

Hierachy of sequence types

Image: Hierachy of sequence types

The indication of a name for elements and attributes must be seen in connection with the XML Schema definitions known for the query evaluation.

If the name and the type for an element are indicated, all elements are accepted which have this name (or which are within the substitution group belonging to this element name) and which are also of the indicated type (or whose type was derived from this type by extension or restriction). For example, the sequence type

element(Employee, Employee_T)

matches Doctor elements according to the example schema. In this case, however, no schema definition for the element name has to be known. This also applies if a * is indicated for the type. In this case, the type of the element is optional; for example, for the sequence type

element(AmbulanceDriver, *)

an element called AmbulanceDriver is accepted, even if such an element is not defined in the schema. Also for the name a * can be indicated, then only the type of the element is taken into account.

An element with empty content and the xsi:nil="true" attribute is only accepted if the key word nillable had been added to the type name. Therefore, the element

<Salary xsi:nil="true"/>

matches the sequence type

element(*, xs:integer nillable)

If for an element only the name is indicated, a Schema definition must be known for this element name. An element is accepted if it has this name or if it belongs to a substitution group of this name. Then the type of the element must also correspond to the type in the Schema definition or must be derived from it by extension or restriction. Therefore, the sequence type

element(AmbulanceDriver)

results in an error since such an element is not defined in our example schema. However, the sequence type

element(Employee)

also accepts a Doctor element because this element belongs to its substitution group.

In XML Schema it is possible to define elements not globally, but locally, which means only in the context of another element or of a complex type. XQuery allows the indication of a context path in order to be able to also use such elements. This is more or less a navigation instruction of a global definition to the local element.

In order that an element is accepted, it must have the indicated name and validate against the type which applies in the schema for the local element. For the patient example schema the following sequence type can be used in order to address an element having the name Start and the same type as the Start element locally defined under Surgery:

element(Surgery/Start)

However, an element which matches this sequence type does not necessarily have to be a child of an Surgery element, but only has to correspond to the structure of the type expected for Start below Surgery!

In case the global definition from where the navigation is performed is a type definition and not an element definition, the type name is bound in type(), as with

element(type(Person_T)/E-mail)

For attributes the rules mentioned apply analogously.

 

Source: "XQuery – Grundlagen und fortgeschrittene Methoden", dpunkt-Verlag, Heidelberg (2004)

<< backnext >>