This section describes the XQuery basic items listed in the following table.
Table 1-48 XQuery basic items
No. | Basic item | Summary |
---|---|---|
1 | Focus | The XQuery item information that is to be evaluated when the XQuery expression is evaluated. |
2 | Qualified name | Names used in XQuery in order to identify XML elements, XML attributes, XQuery functions, and XQuery variables. |
3 | XQuery data type | Types in which nodes and atomic values are entered in the XQuery data model. |
4 | Atomization | The process of converting an XQuery sequence into an XQuery sequence consisting of only atomic values. |
5 | Implicit type conversion to Boolean values | The process of automatically converting to Boolean values any values other than Boolean values that are the target of evaluation in the XQuery expression. |
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 item | Summary |
---|---|---|
1 | Context item | XQuery item that is the target of evaluation |
2 | Context position | Position of the context item in the XQuery sequence composed of context items |
3 | Context size | Number of context items |
The following sections describe each information item in detail.
Holds the XQuery item that is the target of evaluation when the XQuery expression is evaluated.
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.
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"> |
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
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. | Prefix | XML namespace URI |
---|---|---|
1 | xml | http://www.w3.org/XML/1998/namespace |
2 | xs | http://www.w3.org/2001/XMLSchema |
3 | xsi | http://www.w3.org/2001/XMLSchema-instance |
4 | fn | http://www.w3.org/2006/xpath-functions |
5 | err | http://www.w3.org/2005/xqt-errors |
6 | hi-fn | http://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 name | Prefix | Local name |
---|---|---|---|
1 | xs:string | xs | string |
2 | fn:data | fn | data |
3 | element_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 name | Prefix | Local name | Associated XML namespace URI |
---|---|---|---|---|
1 | xxx:element_name | xxx | element_name | http://www.hitachi.com |
2 | yyy:element_name | yyy | element_name | http://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. | Classification | Characters that can be used in the prefix and local name | Beginning character? |
---|---|---|---|
1 | One-byte character code characters | Lower-case letters (A to Z) | Y |
2 | Lower-case letters (a to z) | Y | |
3 | Numeric characters (0 to 9) | N | |
4 | Katakana characters | Y | |
5 | Two-byte character code | All two-byte character code characters | Y |
6 | Special characters (one-byte character code) | Period (.) | N |
7 | Hyphen or minus sign (-) | N | |
8 | Underscore (_) | Y |
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.
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. | Classification | XQuery data type | Explanation |
---|---|---|---|
1 | Character string data type | xs:string | Type representing character strings. |
2 | Numeric data type | xs:decimal | Type representing fixed-point numbers of up to 38 digits. |
3 | xs:int | Type representing integer values in the range -2147483648 to 2147483647. | |
4 | xs:double | Type representing double-precision floating-point numbers with a value of approximately ![]() ![]() | |
5 | Time data type | xs:dateTime | Type 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). |
6 | xs:date | Type 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). | |
7 | xs:time | Type 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). | |
8 | Other data types | xs:hexBinary | Type representing binary data as a sequence of hexadecimal characters (sequence of characters 0 to 9, a to f, and A to F). |
9 | xs:boolean | Type representing a logical value of TRUE or FALSE. | |
10 | Undefined data type | xs:untypedAtomic | Type representing an atomic value whose type is undefined. |
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:
XQuery-data-type-name ( argument ) |
The following table lists all possible XQuery data type conversions.
Table 1-55 Convertible XQuery data types
XQuery data type before conversion | XQuery data type after conversion | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
Numeric data types | Character string data type | Time data types | Other data types | |||||||
xs: double | xs: decimal | xs: int | xs: string | xs: dateTime | xs: date | xs: time | xs: hexBinary | xs: boolean | xs: untyped Atomic | |
xs:double | Y | C | C | Y | N | N | N | N | Y | Y |
xs:decimal | Y | Y | C | Y | N | N | N | N | Y | Y |
xs:int | Y | Y | Y | Y | N | N | N | N | Y | Y |
xs:string | C | C | C | Y | C | C | C | C | C | Y |
xs:dateTime | N | N | N | Y | Y | Y | Y | N | N | Y |
xs:date | N | N | N | Y | Y | Y | N | N | N | Y |
xs:time | N | N | N | Y | N | N | Y | N | N | Y |
xs:hexBinary | N | N | N | Y | N | N | N | Y | N | Y |
xs:boolean | Y | Y | Y | Y | N | N | N | N | Y | Y |
xs:untyped Atomic | C | C | C | Y | C | C | C | C | C | Y |
Table 1-56 Rules for conversion to xs:string type and xs:untypedAtomic type
No. | Before conversion | Conversion result | |
---|---|---|---|
XQuery data type | Conditions on value | ||
1 | xs:string xs:untypedAtomic | All | Not converted. |
2 | xs:int | All | Converted to XQuery integer literal format. Leading zeros are removed, and a minus sign (-) is added for values less than zero. |
3 | xs:decimal | Fractional part is 0 | |
4 | Fractional part is not 0 | Converted to XQuery decimal literal format. Leading zeros (except in the ones column) and trailing zeros are removed, and a minus sign (-) is added for values less than zero. | |
5 | xs:double | Absolute value is at least 0.000001 but less than 1000000 | Follows xs:decimal type conversion rules (No. 3 and 4) above. |
6 | Positive 0 | Converted to 0 | |
7 | Negative 0 | Converted to -0. | |
8 | Positive maximum value | Converted to INF. | |
9 | Negative maximum value | Converted to -INF. | |
10 | NaN (not a number) | Converted to NaN. | |
11 | Other than the above | Converted to a string in XQuery decimal literal format into which the mantissa is converted, followed by E, followed by a string in XQuery integer literal format into which the exponent part is converted. Leading zeros are removed. The integer part of the mantissa is one non-zero digit. Trailing zeros are removed from the fractional mantissa (except from the tenths column). A minus sign (-) is added for values less than zero. | |
12 | xs:boolean | TRUE | Converted to true. |
13 | FALSE | Converted to false. | |
14 | xs:dateTime | All | Converted to the format YYYY-MM-DDThh:mm:ss.s...s, where YYYY is the year, MM the month, DD the day, hh the hour, mm the minute, ss the seconds, and s...s the fractional seconds. If the fractional seconds part is not 0, any trailing zeros are removed from the fractional seconds. If the fractional seconds part is 0, it is not displayed. |
15 | xs:date | All | Converted to the format YYYY-MM-DD, where YYYY is the year, MM the month, and DD the day. |
16 | xs:time | All | Converted to the format hh:mm:ss, where hh is the hour, mm the minutes, and ss the seconds. |
17 | xs:hexBinary | All | A hexadecimal character sequence is returned unchanged. However, A to F is converted to upper case. |
Table 1-57 Rules for conversion to xs:double type
No. | Before conversion | Conversion result | |
---|---|---|---|
XQuery data type | Conditions on value | ||
1 | xs:double | All | Not converted. |
2 | xs:int xs:decimal | All | Converted to the value of the corresponding xs:double type. |
3 | xs:boolean | TRUE | Converted to 1.0E0. |
4 | FALSE | Converted to 0.0E0. | |
5 | xs:string | INF | Converted to positive infinity. |
6 | -INF | Converted to negative infinity. | |
7 | NaN | Converted to NaN (not a number). | |
8 | XQuery numeric literal format character string# | First converted to the corresponding numeric data type, then converted to xs:double type. | |
9 | Other than the above | Cannot be converted. | |
10 | xs:untypedAtomic | All | First converted to the xs:string type, then converted to xs:double type. |
Table 1-58 Rules for conversion to xs:decimal type
No. | Before conversion | Conversion result | |
---|---|---|---|
XQuery data type | Conditions on value | ||
1 | xs:decimal | All | Not converted. |
2 | xs:double | Positive 0 | Converted to 0. |
3 | Negative 0 | Converted to 0. | |
4 | Positive infinity | Cannot be converted. | |
Negative infinity | |||
NaN (not a number) | |||
5 | Values where the integer part is not more than 38 digits long. | Converted to the xs:decimal type value, not exceeding 38 digits in length, that is numerically closest to the pre-conversion value. If there are two possible values, it is converted to the value closer to zero. | |
6 | Other than the above | Cannot be converted. | |
7 | xs:int | All | Converted to the corresponding xs: decimal type value. |
8 | xs:boolean | TRUE | Converted to 1. |
9 | FALSE | Converted to 0. | |
10 | xs:string | XQuery numeric literal format character string# | First converted to the corresponding numeric data type, then converted to xs:decimal type. |
11 | Other than the above | Cannot be converted. | |
12 | xs:untypedAtomic | All | First converted to xs:string type, then converted to xs:decimal type. |
Table 1-59 Rules for conversion to xs:int type
No. | Before conversion | Conversion result | |
---|---|---|---|
XQuery data type | Conditions on value | ||
1 | xs:int | All | Not converted. |
2 | xs:decimal | Values that fall between the minimum and maximum values of the xs:int type once the digits after the decimal point are truncated. | Converted to a value in which the digits after the decimal point are truncated. |
3 | Other than the above | Cannot be converted. | |
4 | xs:double | Positive 0 | Converted to 0. |
5 | Negative 0 | Converted to 0. | |
6 | positive infinity | Cannot be converted. | |
negative infinity | |||
NaN (not a number) | |||
7 | Values that fall between the minimum and maximum values of the xs:int type once the digits after the decimal point are truncated. | Converted to a value in which the digits after the decimal point are truncated. | |
8 | Other than the above | Cannot be converted. | |
9 | xs:boolean | TRUE | Converted to 1. |
10 | FALSE | Converted to 0. | |
11 | xs:string | XQuery numeric literal format character string# | First converted to the corresponding numeric data type, then converted to the xs:int type. |
12 | Other than the above | Cannot be converted. | |
13 | xs:untypedAtomic | All | First converted to the xs:string type, then converted to xs:int type. |
Table 1-60 Rules for conversion to xs:dateTime type
No. | Before conversion | Conversion result | |
---|---|---|---|
XQuery data type | Conditions on value | ||
1 | xs:dateTime | All | Not converted. |
2 | xs:date | All | The date part is equal to the value before conversion, and the time part is converted to the value 00:00:00. |
3 | xs:string | xs:dateTime type character string representation format value | Converted to the value of the corresponding character string representation. |
4 | Other than the above | Cannot be converted. | |
5 | xs:untypedAtomic | All | First converted to the xs:string type, then converted to the xs:dateTime type. |
Table 1-61 Rules for conversion to xs:date type
No. | Before conversion | Conversion result | |
---|---|---|---|
XQuery data type | Conditions on value | ||
1 | xs:date | All | Not converted. |
2 | xs:dateTime | All | Converted to a value that is equal to the value of the date part before conversion. |
3 | xs:string | xs:date type character string representation format value | Converted to the value of the corresponding character string representation. |
4 | Other than the above | Cannot be converted. | |
5 | xs:untypedAtomic | All | First converted to the xs:string type, then converted to the xs:date type. |
Table 1-62 Rules for conversion to xs:time type
No. | Before conversion | Conversion result | |
---|---|---|---|
XQuery data type | Conditions on value | ||
1 | xs:time | All | Not converted. |
2 | xs:dateTime | All | Converted to a value that is equal to the value of the time part before conversion (excluding any fractional seconds). |
3 | xs:string | xs:time type character string representation format value | Converted to the value of the corresponding character string representation. |
4 | Other than the above | Cannot be converted. | |
5 | xs:untypedAtomic | All | First converted to the xs:string type, then converted to the xs:time type. |
Table 1-63 Rules for conversion to xs:boolean type
No. | Before conversion | Conversion result | |
---|---|---|---|
XQuery data type | Conditions on value | ||
1 | xs:boolean | All | Not converted. |
2 | Numeric data type | 0 | Converted to FALSE. |
Positive 0 | |||
Negative 0 | |||
0.0 | |||
0.0E0 | |||
NaN (not a number) | |||
3 | Other than the above | Converted to TRUE. | |
4 | xs:string | true# | Converted to TRUE. |
5 | false# | Converted to FALSE. | |
6 | Other than the above | Cannot be converted. | |
7 | xs:untypedAtomic | All | First converted to xs:string type, then converted to xs:boolean type. |
Table 1-64 Rules for conversion to xs:hexBinary type
No. | Before conversion | Conversion result | |
---|---|---|---|
XQuery data type | Conditions on value | ||
1 | xs:hexBinary | All | Not converted. |
2 | xs:string | Hexadecimal character sequence | Converted to the value of the corresponding xs:hexBinary type. |
3 | Other than the above | Cannot be converted. | |
4 | xs:untypedAtomic | All | First being converted to xs:string type, then converted to xs:hexBinary type. |
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.
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.