1.15.2 Basic items

This section describes the XQuery basic items listed in the following table.

Table 1-48 XQuery basic items

No.Basic itemSummary
1FocusThe XQuery item information that is to be evaluated when the XQuery expression is evaluated.
2Qualified nameNames used in XQuery in order to identify XML elements, XML attributes, XQuery functions, and XQuery variables.
3XQuery data typeTypes in which nodes and atomic values are entered in the XQuery data model.
4AtomizationThe process of converting an XQuery sequence into an XQuery sequence consisting of only atomic values.
5Implicit type conversion to Boolean valuesThe process of automatically converting to Boolean values any values other than Boolean values that are the target of evaluation in the XQuery expression.
Organization of this subsection
(1) Focus
(2) Qualified names
(3) XQuery data types
(4) Atomization
(5) Implicit type conversion to Boolean values

(1) Focus

The focus is the XQuery item information that is the target of evaluation at the time the XQuery expression is evaluated.

The following table describes the information item making up the focus.

Table 1-49 Focus

No.Information itemSummary
1Context itemXQuery item that is the target of evaluation
2Context positionPosition of the context item in the XQuery sequence composed of context items
3Context sizeNumber of context items

The following sections describe each information item in detail.

(a) Context item

Holds the XQuery item that is the target of evaluation when the XQuery expression is evaluated.

(b) Context position

Holds the positions of the context item, in a XQuery sequence composed of context items, at the time the XQuery expression is evaluated. Context position is an integer value starting at 1.

(c) Context size

Holds the number of context items at the time the XQuery expression is evaluated.

The focus shifts as the XQuery expression is sequentially evaluated. This is illustrated in the following example.

Example:

XML document to be evaluated:

<bookinfo book_id="452469630​">
 <title>Relational Databases Explained</title>
 <author>Jeff Jones</author>
 <author>Bob Adams</author>
</bookinfo>

XQuery expression:

/bookinfo/author/text()

In this example XQuery expression, bookinfo, author, and text() will be evaluated in the given order. The shifting of the focus as this happens is shown in the following figure.

Figure 1-16 Flow of the shifting of the focus

[Figure]

Explanation
  1. Before the evaluation of the XQuery expression begins, the context items are initialized in the document node. The context position in the document node is set to 1, and the context size is set to 1.
  2. When the bookinfo portion of the XQuery expression is evaluated, the context item moves from the document node down to the bookinfo element node. Because there is one context item, the context position in the bookinfo element node is set to 1, and the context size is set to 1.
  3. When the author portion of the XQuery expression is evaluated, the context item moves from the bookinfo element node down to the author element node. The children of the bookinfo element node include two author element nodes. So, according to the document order, the context position of the first author element node is set to 1, the context position of the second author element node is set to 2, and the context size is set to 2.
  4. When the text() portion of the XQuery expression is evaluated, the context item moves from the author element node down to the text node. Because the children of the author element node include two text nodes, the context position of the text node of the child of the first author element node is set to 1, the context position of the text node of the child of the second author element node is set to 2, and the context size is set to 2.

(2) Qualified names

The names used in XQuery to identify XML elements, XML attributes, XQuery functions, and XQuery variables are called qualified names. A qualified name is composed of a prefix, the colon character, and a local name. Using an XML namespace declaration (for details about XML namespace declarations, see 1.15.5 XQuery declaration), the user can associate an XML namespace URI with a prefix. An XML namespace URI is a URI that identifies an XML namespace. A local name is a name used within an individual XML namespace.

The following table lists the prefixes that are already defined in HiRDB.

Table 1-50 Prefixes defined in HiRDB

No.PrefixXML namespace URI
1xmlhttp://www.w3.org/XML/1998/namespace
2xshttp://www.w3.org/2001/XMLSchema
3xsihttp://www.w3.org/2001/XMLSchema-instance
4fnhttp://www.w3.org/2006/xpath-functions
5errhttp://www.w3.org/2005/xqt-errors
6hi-fnhttp://www.hitachi.co.jp/Prod/comp/soft1/hirdb/xquery-functions

You may specify a qualified name by omitting the prefix and the colon character and specifying only a local name. A qualified name where the prefix and colon are omitted will be searched for in the default XML namespace. For details about the default XML namespace, see 1.15.5 XQuery declaration. The following table provides examples of qualified names.

Table 1-51 Examples of qualified names

No.Qualified namePrefixLocal name
1xs:stringxsstring
2fn:datafndata
3element_name(omitted)element_name

A name consisting of the XML namespace URI corresponding to a prefix and a local name is called an expand qualified name. Two qualified names are equivalent if their local names and the XML namespace URLs of their expand qualified names are both the same. In this case, even if the prefixes of the two qualified names are different, the two qualified names are considered to be equivalent. For example, the two qualified name listed in the table below have different prefixes. Nevertheless, the two qualified names are considered to be equivalent because their local names and the expand qualified names of their XML namespace URIs are both the same.

Table 1-52 Even with different prefixes, the two qualified names are considered equivalent

No.Qualified namePrefixLocal nameAssociated XML namespace URI
1xxx:element_namexxxelement_namehttp://www.hitachi.com
2yyy:element_nameyyyelement_namehttp://www.hitachi.com

The following table lists the characters that can be used to specify the prefix and local name.

Table 1-53 Characters that can be used in the prefix and local name

No.ClassificationCharacters that can be used in the prefix and local nameBeginning character?
1One-byte character code charactersLower-case letters (A to Z)Y
2Lower-case letters (a to z)Y
3Numeric characters (0 to 9)N
4Katakana charactersY
5Two-byte character codeAll two-byte character code charactersY
6Special characters (one-byte character code)Period (.)N
7Hyphen or minus sign (-)N
8Underscore (_)Y
Legend:
Y: Can be specified at the beginning of a prefix or local name.
N: Cannot be specified at the beginning of a prefix or local name.

The characters that can be used in XQuery prefixes and local names depend on the character code classification specified in the pdsetup command. For details about the pdsetup command, see the manual HiRDB Version 9 Command Reference. For details about the relationships between specific character code classifications and the available characters, see 1.1.5 SQL character set.

(3) XQuery data types

(a) XQuery data types defined in HiRDB

XQuery items must be typed with an XQuery data type in order to be used in XQuery. The table below lists the XQuery data types provided in HiRDB. XQuery data types with a single value are called atomic types. These include the character string data type, numeric data types, time data types, certain other types, and the xs:untypedAtomic type. The value of an atomic type is called an atomic value.

Table 1-54 XQuery data types defined in HiRDB

No.ClassificationXQuery data typeExplanation
1Character string data typexs:stringType representing character strings.
2Numeric data typexs:decimalType representing fixed-point numbers of up to 38 digits.
3xs:intType representing integer values in the range -2147483648​ to 2147483647​.
4xs:doubleType representing double-precision floating-point numbers with a value of approximately [Figure] 4.9 x 10-324 to [Figure] 1.7 x 10308.#
5Time data typexs:dateTimeType representing a particular time on a particular date as a combined date and time value. Expressed in the format YYYY-MM-DDThh:mm:ss[.nn...n]. YYYY represents the year, MM the month, DD the day, hh the hour, mm the minute, ss the seconds, and nn...n the fractional seconds (one to six digits). T is the notation used to separate the date and time. The range of possible values for each element in the format is YYYY: 0001 to 9999 (year), MM: 01 to 12 (month), DD: 01 to the last day of that month (day), hh: 00 to 23 (hour), mm: 00 to 59 (minute), ss: 00 to 59 (second), nnnnnn: 000000 to 999999 (fractional seconds).
6xs:dateType representing a date as the value. Expressed in the format YYYY-MM-DD, where YYYY represents the year, MM the month, and DD the day. The range of possible values for each element in the format is YYYY: 0001 to 9999 (year), MM: 01 to 12 (month), DD: 01 to the last day of that month (day).
7xs:timeType representing a time as the value. Expressed in the format hh:mm:ss, where hh represents the hour, mm the minute, and ss the seconds. The range of possible values for each element in the format is hh: 00 to 23 (hour), mm: 00 to 59 (minute), ss: 00 to 59 (seconds).
8Other data typesxs:hexBinaryType representing binary data as a sequence of hexadecimal characters (sequence of characters 0 to 9, a to f, and A to F).
9xs:booleanType representing a logical value of TRUE or FALSE.
10Undefined data typexs:untypedAtomicType representing an atomic value whose type is undefined.
#
The range of values of floating point numbers depends on the hardware representation.
(b) Constructor function

For each atomic type shown in (a), there is an implicitly defined constructor function that generates that type of atomic value from another atomic value. The constructor function takes the following format:

(c) Convertible XQuery data types

The following table lists all possible XQuery data type conversions.

Table 1-55 Convertible XQuery data types

XQuery data type before conversionXQuery data type after conversion
Numeric data typesCharacter string data typeTime data typesOther data types
xs:
double
xs:
decimal
xs:
int
xs:
string
xs:
dateTime
xs:
date
xs:
time
xs:
hexBinary
xs:
boolean
xs:
untyped
Atomic
xs:doubleYCCYNNNNYY
xs:decimalYYCYNNNNYY
xs:intYYYYNNNNYY
xs:stringCCCYCCCCCY
xs:dateTimeNNNYYYYNNY
xs:dateNNNYYYNNNY
xs:timeNNNYNNYNNY
xs:hexBinaryNNNYNNNYNY
xs:booleanYYYYNNNNYY
xs:untyped
Atomic
CCCYCCCCCY
Legend:
Y: Can be converted.
C: Can be converted depending on the value.
N: Cannot be converted.
#
Applies if removing leading and trailing whitespace (one-byte space (X'20'), tab (X'09'), NL (X'0A'), and CR (X'0D')) results in the XQuery numeric literal format.
#
Applies if removing leading and trailing whitespace (one-byte space (X'20'), tab (X'09'), NL (X'0A'), and CR (X'0D')) results in the XQuery numeric literal format.
#
Applies if removing leading and trailing whitespace (one-byte space (X'20'), tab (X'09'), NL (X'0A'), and CR (X'0D')) results in the XQuery numeric literal format.
#
Applies if removing leading and trailing whitespace (one-byte space (X'20'), tab (X'09'), NL (X'0A'), and CR (X'0D')) results in the XQuery numeric literal format. Not case-sensitive.

(4) Atomization

Atomization is the process of converting an XQuery sequence to an XQuery sequence consisting of only atomic values. In XQuery, atomization is performed when evaluating the following expressions, for which an XQuery sequence that consists of only atomic values is required:

The atomization result is the result of calling the XQuery fn:data function on the XQuery sequence. For details about the fn:data function, see 1.15.8 XQuery functions.

(5) Implicit type conversion to Boolean values

In XQuery, when a value other than a Boolean value is evaluated in a place where a Boolean value (xs:boolean type value) is required, it is automatically converted to a Boolean value. The result of converting to a Boolean value will be the result of calling the XQuery fn:boolean function on the XQuery sequence. For details about the fn:boolean function, see 1.15.8 XQuery functions.