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

Document nodes

A document node represents a XML document. XQuery has a wider definition of a XML document than the XML specification. Therefore, it is not required that there is exactly one element node as child of the document node. The textual value of a document node results from the concatenation of the textual values of all text nodes which are descendants of the document node.

In XQuery, a document node can be generated with a computed constructor of the form document {Expr}:

document {<Doctor>Emil Miller</Doctor>}

The nodes being added as children of this new document nodes lose all type information, meaning the types xs:anyType (for element nodes) and xs:anySimpleType (for attribute nodes) are assigned to them. It is not enforced that a document is generated according to XML 1.0 which, for example, has exactly one root element.

Attribute nodes

Attribute nodes correspond to the attributes of XML elements. The textual value of such a node results from the attribute value converted to xs:string. The typed value of the attribute node is obtained from the textual value by validation against a schema (and thus assignment of the type defined in the schema).

An attribute node can be generated via a computed constructor whose key word attribute is followed by the name of the attribute (as constant QName or as expression in an evaluation context) and its value (in an evaluation context). Atomisation is applied in each case to the values in the evaluation contexts. The value is always converted to xs:string, so it may not have to correspond to the type of the attribute. The following call of the computed attribute constructor generates an attribute whose name results from the value of the $a variable and whose value is 42:

attribute {$a} {6*7}

Such a constructor can be used in direct as well as in computed element constructors in order to generate attribute nodes to the appropriate element. For example,

<Salary>{attribute Currency {"€"}, "10000"}</Salary>

returns the element <Salary Currency="€">10000</Salary>. Similarly, the following could have been written:

element Salary {attribute Currency {"€"}, "10000"}


<Salary Currency="€">10000</Salary>

Attribute nodes differ from namespace nodes. As a consequence, the name of an attribute must not be xmlns or must not begin with xmlns:.


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

<< backnext >>