• +49-(0)721-402485-12
Your experts for XML, XQuery and XML Databases

Element nodes

An element node represents an element from XML 1.0. The textual value of an element node results from the concatenation of all text nodes which are descendants of this element node. In addition, an element has a typed value in case it has no complex content, which means if it does not only have child elements.

The typed value results from the validation of the textual value against the type definition according to XML Schema (so, the typed value has, for example, the xs:integer type if the element has the simple type xs:integer according to the schema definition). If the element has the xdt:untypedAny type (an undetermined complex type), the typed value is of xdt:untypedAtomic type (the undetermined atomic type).

For the generation of an element node, two different constructors exist: the direct element constructor and the computed element constructor.

The direct element constructor

The direct element constructor uses the familiar XML notation, for example:

<Doctor ID="Doctor_01">Max Müller</Doctor>

In attribute values and in the element content, references to predefined entities (for example &lt;) and character references (for example &#x20;) are permitted and resolved during the construction:

<Competence>Elderly care</Competence>

Instead of a constant content, also an expression can be indicated which is evaluated during the construction. In order to be able to distinguish an expression from a literal content, it is enclosed into curly brackets. (The XQuery specification calls this an enclosed expression. This signals a new "evaluation context", which means not a literal taking over, but an expression evaluation). So, by means of the constructor

<Salary>{12*3000}</Salary>

the following element

<Salary>36000</Salary>

is generated. If, exceptionally, a curly bracket shall not mark an expression, it must be dublicated. The evaluation of the expressions in curly brackets results in sequences of nodes and atomic values. In case attribute nodes result from this, they become attributes of the surrounding element. However, these attribute nodes must be situated before other nodes, otherwise an error is reported. Element nodes become children of the surrounding element.

More nested CDATA and element constructors as well as constructors for comments and processing instructions do not have to be enclosed in curly brackets, as the following example shows:

 

<Volunteer ID="vol_01"><!-- inserted 1.1.2004-->
<Name>
<FirstName>Daniela</FirstName>
<LastName>Baumann</LastName>
</Name>
<Address>
<Street>Potsdamer Straße</Street>
<HouseNo>62</HouseNo>
<City>Berlin</City>
<Country>D</Country>
<PostalCode>14145</PostalCode>
</Address>
<DateOfBirth> {xs:date("1982-07-23")} </DateOfBirth>
<Phone>+49 30-234626</Phone>
<Number>07</Number>
<Competence>Elderly care</Competence>
<VocationalClass>Nurse</VocationalClass>
</Volunteer>

The exact syntax of the direct element constructor is:

DirElemConstructor::=<QName AttributeList (/> | (> ElementContent* </QName>))
ElementContent::=ElementContentChar| {{ | }} | DirElemConstructor
| EnclosedExpr | CdataSection | CharRef
| PredefinedEntityRef | XmlComment | XmlPI
AttributeList::=( QName = AttributeValue )*
EnclosedExpr::={Expr}

Attribute values

An expression in curly brackets is also allowed in an attribute value. By atomisation the result of the evaluation of an expression in an attribute value becomes a sequence of atomic values which in turn are converted to values of xs:string type. All these character strings are concatenated and result in the attribute value. All space characters are converted to common whitespaces (U+0020). So, for example, the constructor

<Doctor Salary="YearlySalary {<Calculation>
{12*3000}</Calculation>} Euros"/>

becomes the element:

<Doctor Salary="YearlySalary 36000 Euros"/>

 

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

<< backnext >>