# Difference between revisions of "PsychoPathXPathProcessor/UserManual"

Line 163: | Line 163: | ||

=== 2.5 Arithmetic Expressions === | === 2.5 Arithmetic Expressions === | ||

− | + | ==== Unary ==== | |

minus and plus: The unary minus operator changes the sign of a number. For example -1 is minus one, and -1e0 is the double value negative -1. | minus and plus: The unary minus operator changes the sign of a number. For example -1 is minus one, and -1e0 is the double value negative -1. | ||

− | + | ==== Multiplication ==== | |

and division: The operator * multiplies two numbers. If the operands are of different types, XPath 2.0 specifications say that one of them is promoted to the type of the other but this is currently unsupported in PsychoPath. The result is the same type as the operands after promotion. <br> The operator div divides two numbers. Dividing two integers produces a double; in other cases the result is the same type as the operands. <br> The operator idiv performs integer division. For example, the result of 10 idiv 3 is 3. <br> The mod operator returns the modulus (or remainder) after division. <br> The operators * and div may also be used to multiply or divide a range by a number. For example, (1 idiv 1 to 3) returns the result: 1) xs:integer: 1 2) xs:integer: 2 3) xs:integer: 3 | and division: The operator * multiplies two numbers. If the operands are of different types, XPath 2.0 specifications say that one of them is promoted to the type of the other but this is currently unsupported in PsychoPath. The result is the same type as the operands after promotion. <br> The operator div divides two numbers. Dividing two integers produces a double; in other cases the result is the same type as the operands. <br> The operator idiv performs integer division. For example, the result of 10 idiv 3 is 3. <br> The mod operator returns the modulus (or remainder) after division. <br> The operators * and div may also be used to multiply or divide a range by a number. For example, (1 idiv 1 to 3) returns the result: 1) xs:integer: 1 2) xs:integer: 2 3) xs:integer: 3 | ||

− | + | ==== Addition ===== | |

and subtraction: The operators + and - perform addition and subtraction of numbers, in the usual way. Once again, if the operands are of different types, XPath 2.0 specifications say one of them is promoted but numeric type promotion is currently unsupported by PsychoPath. The result is of the same type as the operands. | and subtraction: The operators + and - perform addition and subtraction of numbers, in the usual way. Once again, if the operands are of different types, XPath 2.0 specifications say one of them is promoted but numeric type promotion is currently unsupported by PsychoPath. The result is of the same type as the operands. | ||

Line 177: | Line 177: | ||

Examples of above would be: | Examples of above would be: | ||

− | + | -(5 + 7) | |

+ | result: 1) xs:integer: -12 | ||

− | + | - xs:float(’1.23’) | |

+ | result: 1) xs:float: -1.23 | ||

+ | |||

+ | - xs:double(’1.23’) | ||

+ | result: 1) xs:double: -1.23 | ||

+ | |||

+ | (+5 - +7) | ||

+ | result: 1) xs:integer: -2 | ||

+ | |||

+ | (1 to 5 div 0 ) | ||

+ | result: FAIL (division by zero!) | ||

+ | |||

+ | 5{*}6{*}10{*}5{*}96 div 20 div 3 div 1 | ||

+ | result: 1) xs:decimal: 2400.0 | ||

+ | |||

+ | 31 mod 15 | ||

+ | result: 1) xs:integer: 1 | ||

=== 2.6 Range expressions === | === 2.6 Range expressions === |

## Revision as of 14:43, 9 August 2009

## Contents

- 1 1 How to feed Psychopath XPath expressions
- 2 2 How to use the XPath 2.0 grammar with PsychoPath
- 2.1 2.1 Constants
- 2.2 2.2 Path expressions
- 2.3 2.3 Axis steps
- 2.4 2.4 Set difference, intersection and Union
- 2.5 2.5 Arithmetic Expressions
- 2.6 2.6 Range expressions
- 2.7 2.7 Comparisons
- 2.8 2.8 Conditional Expressions
- 2.9 2.9 Quantified Expressions
- 2.10 2.10 And, Or expressions
- 2.11 2.11 SequenceType Matching Expressions

- 3 3 How to use XPath 2.0 functions with PsychoPath
- 3.1 3.1 Accessors
- 3.2 3.2 The Error and Trace Functions
- 3.3 3.3 Constructor Functions
- 3.4 3.4 Functions on Numeric Values
- 3.5 3.5 Functions to Assemble and Disassemble Strings
- 3.6 3.6 Compare and Other Functions on String Values
- 3.7 3.7 Functions Based on Substring Matching
- 3.8 3.8 String Functions that Use Pattern Matching
- 3.9 3.9 Functions on Boolean Values
- 3.10 3.10 Component Extraction Functions on Durations, Dates and Times
- 3.11 3.11 Functions Related to QNames
- 3.12 3.12 Functions on Nodes
- 3.13 3.13 General Functions on Sequences
- 3.14 3.14 Functions That Test the Cardinality of Sequences
- 3.15 3.15 Deep-Equal, Aggregate Functions, and Functions that Generate Sequences
- 3.16 3.16 Context Functions

- 4 4 How to use XPath 2.0 operators with PsychoPath
- 4.1 4.1 Operators on Numeric Values
- 4.2 4.2 Comparison of Numeric Values
- 4.3 4.3 Operators on Boolean Values
- 4.4 4.4 Comparisons of Duration, Date and Time Values
- 4.5 4.5 Arithmetic Functions on Durations
- 4.6 4.6 Arithmetic Functions Dates and Times
- 4.7 4.7 Operators Related to QNames And Nodes
- 4.8 4.8 Union, Intersection and Except
- 4.9 4.9 Operators that Generate Sequences

## 1 How to feed Psychopath XPath expressions

Since PsychoPath has been implemented as an external library and not as a complete program, in order to use it, it needs to be accessed from inside another program. To process XPath 2.0 expressions using PsychoPath from another programs one needs to go through the following process:

- Load the XML document
- Optionally validate the XML document
- Initialize static and dynamic context in respect to the document root
- Parse the XPath 2.0 expression
- Statically verify the XPath 2.0 expression
- Evaluate the XPath 2.0 expression in respect to the XML document

To give a better idea of how this process actually works, we’ll go through an example of processing and evaluating the string expression “Hello World!”. In this example the XML document that we load is called “XPexample.xml”.

All 5 main steps have been explained in detail in Chapter 5, User Interface, so below is just a brief code summary:

/** * First load and optionally validate the XML document */ // Create an InputStream from the XML document InputStream is = new FileInputStream(“XPexample.xml”); // Initializing the Xerces DOM loader. DOMLoader loader = new XercesLoader(); // Optionally set flag to validate XML document loader.setvalidating(validate); // Loads the XML document and stores the DOM root Document doc = loader.load(is); /** * Dynamic contexts must be initialised to defaults * dependent on the XML Schema. */ // Extracting the schema from DOM root of Xpexpression.xml. ElementPSVI rootPSVI = (ElementPSVI)doc.getDocumentElement(); XSModel schema = rootPSVI.getSchemaInformation(); // Initialising the DynamicContext. DynamicContext dc = new DefaultDynamicContext(schema, doc); // Register the namespaces of the XPath 2.0 predefined datatypes dc.addnamespace(“xs”,”http://www.w3.org/2001/XMLSchema”); // Register the XPath 2.0 standard functions dc.addfunctionlibrary(new FnFunctionLibrary()); dc.addfunctionlibrary(new XSCtrLibrary()); /** * Parsing the XPath 2.0 expression into an AST representation */ // Initialises PsychoPath’s supplied parser. XPathParser xpp = new JflexCupParser(); // Parses the XPath expression. XPath xp = xpp.parse(xpath); /** * Static check the AST to verift structural validity of * XPath 2.0 expression */ // Initilising StaticChecker. StaticChecker namecheck = new StaticNameResolver(sc); // Static Checking the Xpath expression ’Hello World!’ namecheck.check(xp); /** * Evaluate the XPath 2.0 expression */ // Initialising the evaluator with DynamicContext and the name // of the XML document XPexample.xml as parameters. Evaluator eval = new DefaultEvaluator(dc, doc); // Evaluates the XPath 2.0 expression, storing the result // in the ResultSequence ResultSequence rs = eval.evaluate(xp);

XPath 2.0 defines everything to be a sequence of items, including the arguments to expressions and the result of operations. Thus, the overall result of an XPath expression evaluation is also a sequence of items. PsychoPath uses the class ResultSequence as a Collections wrapper to store these sequences and therefore, the result of an evaluation is of this type also. The ResultSequence consists of zero or more items; an item may be a node or a simple-value. “Hello World!” is an example of a single value with length 1. A general sequence could be written as (“a”, “s”, “d”, “f”).

Extraction of certain items from the ResultSequence class is described below, with details of the different operations that one might apply on the ResultSequence. Consider that ’rs’ is the ResultSequence, then:

// Will return the number of elements in the sequence, in this // case of ’Hello World!’ expression size = 1. rs.size(); // Will return the n’th element in the sequence, in this case of // ’Hello World!’, if n = 1, then it will return // XSString of “Hello World!”, but if n = 2, it will return // Empty Result. rs.get(n); //Will return true if the sequence is empty. rs.empty(); // Will return the first element of the sequence, // in this example it will return XSString of “Hello World!” rs.first()

However, all the items extracted will be of the type’s base class AnyType and need to be casted into its actual subtype.

Certain operations always return a particular type and using this knowledge, the extracted item can be immediately casted. In our example “Hello World!” returns a string (easily known as it is inside the quotes ’ ’ ), so this can safely be casted as such:

'''XSString xsstring = (XSString)(rs.first());'''

The actual result can now be extracted from this XSString in the following manner:

'''String str = xsstring.value(); '''

The details of how to cast extracted items from AnyType into their actual subtypes with examples is in the next section on How to use each production in the grammar.

However, if the expected return type is unknown or multiple types are possible, the types hierarchy can be traversed in a breadth first manner making use of the Java instanceof operator to ascertain the actual type.This is addressed in full detail in Chapter 5, Section 2.6.

## 2 How to use the XPath 2.0 grammar with PsychoPath

In this section we will try to give you an overview of the XPath 2.0 grammar in general and how each production in the grammar should be used with PsychoPath. For the formal specifications, see the W3C web-site for XPath 2.0 specification http://www.w3.org/TR/xpath20.

### 2.1 Constants

String literals are written as “Hello” or ‘Hello’. In each case the opposite kind of quotation mark can be used within the string: ‘He said “Hello” ’ or “London is a big city”. To feed PsychoPath, “ ‘Hello World!’ ”or “ “Hello World!” ” can be used to feed it with strings. Remember that the ResultSequence returns AnyType so since a string is being expected as the result, first it has to be casted in the code like this:

XSString xsstring = (XSString)(rs.first());

Numeric constants follow the Java rules for decimal literals: for example, 4 or 4.67; a negative number can be written as -3.05. The numeric literal is taken as a double precision floating point number if it uses scientific notation (e.g. 1.0e7), as a fixed point decimal if it includes a decimal point, or as an integer otherwise. When extracting number literals from the ResultSequence, possible types to be returned include *XSDecima*l (e.g. : xs:decimal: 4.67),*XSInteger *(e.g. : xs:integer: 4) or *XSDouble* (e.g. : xs:double 1e0). All of which need to be casted in the same manner as stated before: from AnyType to their corresponding types.

There are no boolean constants as such: *true, false* instead the function calls **true()** and **false()** are used.

Constants of other data types can be written using constructors. These look like function calls but require a string literal as their argument. For example, **xs:float(“10.7”)** produces a single-precision floating point number.

To see the full list of the other data types that PsychoPath implements, See Appendix ??.

### 2.2 Path expressions

A path expression is a sequence of steps separated by the **/** or **//** operator. For example, **../@desc** selects the desc attribute of the parent of the context node.

In XPath 2.0, path expressions have been generalized so that any expression can be used as an operand of **/**, (both on the left and the right), as long as its value is a sequence of nodes. For example, it is possible to use a union expression (in parentheses) or a call to the id() function.

In practice, it only makes sense to use expressions on the right of **"/"** if they depend on the context item. It is legal to write $x/$y provided both $x and $y are sequences of nodes, but the result is exactly the same as writing * ./$y*.

Note that the expressions **./$X** or **$X/.** can be used to remove duplicates from **$X** and sort the results into document order.

The operator **//** is an abbreviation for **/descendant-or-self::node()**. An expression of the form **/E** is shorthand for **root(.)/E**, and the expression **/** on its own is shorthand for **root(.)**.

### 2.3 Axis steps

The basic primitive for accessing a source document is the axis step. Axis steps may be combined into path expressions using the path operators "/" and "//", and they may be filtered using filter expressions in the same way as the result of any other expression.

An axis step has the basic form axis::node-test, and selects nodes on a given axis that satisfy the node-test. The axes available are:

- element: age
- element: age

The rest of the axes act in the same manner.

### 2.4 Set difference, intersection and Union

The expression E1 except E2 selects all nodes that are in E1 unless they are also in E2. Both expressions must return sequences of nodes. The results are returned in document order. For example, @* except @note returns all attributes except the note attribute. The expression E1 intersect E2 selects all nodes that are in both E1 and E2. Both expressions must return sequences of nodes. The results are returned in document order. The expression E1 union E2 selects all nodes that are in either E1 or E2 or both. Both expressions must return sequences of nodes. The results are returned in document order. A complete example of the above expression would be as follows. Consider an XML document which looks like this:

<nodes> <a> <connecteda>A</connecteda> <connecteda>B</connecteda> <connecteda>C</connecteda> </a> <b> <connectedb>B</connectedb> <connectedb>C</connectedb> <connectedb>D</connectedb> </b> </nodes>

then an example of each of the expressions would be:

data(/a/{*}) union data(/b/{*}) result: 1) xs:string: A 2) xs:string: B 3) xs:string: C 4) xs:string: D data(/a/{*}) intersect data(/b/{*}) result: 1) xs:string: B 2) xs:string: C data(/a/{*}) except data(/b/{*}) result: 1) xs:string: D

### 2.5 Arithmetic Expressions

#### Unary

minus and plus: The unary minus operator changes the sign of a number. For example -1 is minus one, and -1e0 is the double value negative -1.

#### Multiplication

and division: The operator * multiplies two numbers. If the operands are of different types, XPath 2.0 specifications say that one of them is promoted to the type of the other but this is currently unsupported in PsychoPath. The result is the same type as the operands after promotion.

The operator div divides two numbers. Dividing two integers produces a double; in other cases the result is the same type as the operands.

The operator idiv performs integer division. For example, the result of 10 idiv 3 is 3.

The mod operator returns the modulus (or remainder) after division.

The operators * and div may also be used to multiply or divide a range by a number. For example, (1 idiv 1 to 3) returns the result: 1) xs:integer: 1 2) xs:integer: 2 3) xs:integer: 3

#### Addition =

and subtraction: The operators + and - perform addition and subtraction of numbers, in the usual way. Once again, if the operands are of different types, XPath 2.0 specifications say one of them is promoted but numeric type promotion is currently unsupported by PsychoPath. The result is of the same type as the operands.

Examples of above would be:

-(5 + 7)

result: 1) xs:integer: -12

- xs:float(’1.23’)

result: 1) xs:float: -1.23

- xs:double(’1.23’)

result: 1) xs:double: -1.23

(+5 - +7)

result: 1) xs:integer: -2

(1 to 5 div 0 )

result: FAIL (division by zero!)

5{*}6{*}10{*}5{*}96 div 20 div 3 div 1

result: 1) xs:decimal: 2400.0

31 mod 15

result: 1) xs:integer: 1

### 2.6 Range expressions

The expression E1 to E2 returns a sequence of integers. For example, 1 to 5 returns the sequence 1, 2, 3, 4, 5. This is useful in for expressions, for example the first five nodes of a node sequence can be processed by writing for $i in 1 to 5 return (//x)[$i]. Another example:

"(1+1 to 10)" result: 1) xs:integer: 2 2) xs:integer: 3 3) xs:integer: 4 4) xs:integer: 5 5) xs:integer: 6 6) xs:integer: 7 7) xs:integer: 8 8) xs:integer: 9 9) xs:integer: 10

### 2.7 Comparisons

The simplest comparison operators are eq, ne, lt le, gt, ge. These compare two atomic values of the same type, for example two integers, two dates, or two strings. (Collation hasn’t been implemented in current version of PsychoPath). If the operands are not atomic values, an error is raised.

The operators =, !=, [[Image:]] , [[Image:]] =, [[Image:]] , and [[Image:]] = can compare arbitrary sequences. The result is true if any pair of items from the two sequences has the specified relationship, for example $A = $B is true if there is an item in $A that is equal to some item in $B.

The operators “is" and “isnot" test whether the operands represent the same (identical) node. For example, “title[1] is *[@note][1]" is true if the first title child is the first child element that has a ‘@note" attribute. If either operand is an empty sequence the result is an empty sequence (which will usually be treated as false).

The operators [[Image:]] [[Image:]] and [[Image:]] [[Image:]] test whether one node precedes or follows another in document order. Consider this XML document:

<book> <title>Being a Dog Is a Full-Time Job</title> <author>Charles M. Schulz</author> <character> <name>Snoopy</name> <friend-of>Peppermint Patty</friend-of> <since>1950-10-04</since> <age>2</age> <qualification>extroverted beagle</qualification> </character> <character> <name>Peppermint Patty</name> <since>1966-08-22</since> <age>4</age> <qualification>bold, brash and tomboyish</qualification> </character> </book>

Examples:

"book/character{[}name="Snoopy"{]} << book/character{[}name="Peppermint Patty"{]}" result: 1) xs:boolean: true "book/character{[}name="Peppermint Patty"{]} << book/character{[}name="Snoopy"{]}" result: 1) xs:boolean: false

### 2.8 Conditional Expressions

XPath 2.0 allows a conditional expression of the form if ( E1 ) then E2 else E3. For example, if (@discount) then @discount else 0 returns the value of the discount attribute if it is present, or zero otherwise.

### 2.9 Quantified Expressions

The expression “some $x in E1 satisfies E2" returns true if there is an item in the sequence E1 for which the effective boolean value of E2 is true. Note that E2 must use the range variable $x to refer to the item being tested; it does not become the context item. For example, some $x in @* satisfies $x eq "" is true if the context item is an element that has at least one zero-length attribute value.

Similarly, the expression every $x in E1 satisfies E2 returns true if every item in the sequence given by E1 satisfies the condition. Example:

### 2.10 And, Or expressions

The expression E1 and E2 returns true if the effective boolean values of E1 and E2 are both true. The expression E1 or E2 returns true if the effective boolean values of either or both of E1 and E2 are true. Example: (for a truth table)

"1 and 1" result: 1) xs:boolean: true "1 and 0" result: 1) xs:boolean: false "1 or 0" result: 1) xs:boolean: true "0 or 1" result: 1) xs:boolean: true

### 2.11 SequenceType Matching Expressions

The rules for SequenceType matching compare the actual type of a value with an expected type. These rules are a subset of the formal rules that match a value with an expected type defined in XQuery 1.0 and XPath 2.0 Formal Semantics<ref name="ftn2">http://www.w3.org/TR/xpath20/#XQueryFormalSemantics</ref>, because the Formal Semantics must be able to match a value with any XML Schema type, whereas the rules below only match values against those types expressible by the SequenceType syntax.

Some of the rules for SequenceType matching require determining whether a given type name is the same as or derived from an expected type name. The given type name may be "known" (defined in the in-scope schema definitions), or "unknown" (not defined in the in-scope schema definitions). An unknown type name might be encountered, for example, if a source document has been validated using a schema that was not imported into the static context. In this case, an implementation is allowed (but is not required) to provide an implementation-dependent mechanism for determining whether the unknown type name is derived from the expected type name. For example, an implementation might maintain a data dictionary containing information about type hierarchies. consider the following XML document:

<sorbo> <is>elite</is> <!-- life sux --> </sorbo>

then, the following are some example of SequenceType matchings:

"element({*})" result: 1) element: sorbo "element(elite)" result: Empty results "sorbo/comment()" result: 1) comment: life sux "data(/sorbo/comment())" result: 1) xs:string: life sux "sorbo/node()" result: 1) text: 2) element: is

3) comment: life sux 4) text:

## 3 How to use XPath 2.0 functions with PsychoPath

The aim of this section is to give the user an overview of the available XPath 2.0 functions that are implemented in PsychoPath. For the formal specifications, see the W3C web-site for XPath 2.0 functions and operators<ref name="ftn3">http://www.w3.org/TR/xpath-functions/</ref>.

### 3.1 Accessors

In order for PsychoPath to operate on instances of the XPath 2.0 data model, the model must expose the properties of the items it contains. It does this by defining a family of accessor functions. These functions are not available to users or applications to call directly. Instead, they are descriptions of the information that an implementation of the model must expose to applications.

#### 3.1.1 Example

data(‘string’)

from within a Java application, in order to extract the result from the result sequence, one would have to use this code:

String n = ((XSString)rs.first()).stringvalue(); println(n);

in order to get the result of ‘string’

### 3.2 The Error and Trace Functions

### 3.3 Constructor Functions

#### 3.3.1 Example

xs:dateTime("2002-02-01T10:00:00+06:00")

from within a Java application, in order to extract the result from the result sequence, one would have to use this code:

String n = ((XSDateTime)rs.first()).stringvalue(); println(n);

in order to get the result of ‘2002-02-01T04:00:00Z’

### 3.4 Functions on Numeric Values

#### 3.4.1 Example

ceiling(xs:float(‘10.4’))

from within a Java application, in order to extract the result from the result sequence, one would have to use this code:

float n = ((XSFloat)rs.first()).floatvalue(); println(n);

in order to get the result of ‘11.0’

### 3.5 Functions to Assemble and Disassemble Strings

#### 3.5.1 Example

codepoints-to-string(0111)

String n = ((XSString)rs.first()).stringvalue(); println(n);

in order to get the result of ‘o’

### 3.6 Compare and Other Functions on String Values

#### 3.6.1 Example

concat(‘un’, ‘grateful’)

String n = ((XSString)rs.first()).stringvalue(); println(n);

in order to get the result of ‘ungrateful’

### 3.7 Functions Based on Substring Matching

#### 3.7.1 Example

contains("abc", "edf")

boolean n = ((XSBoolean)rs.first()).value(); println(n);

in order to get the result of ‘false’

### 3.8 String Functions that Use Pattern Matching

#### 3.8.1 Example

matches(‘abcd’, ‘abcd’)

boolean n = ((XSBoolean)rs.first()).value(); println(n);

in order to get the result of ‘true’

### 3.9 Functions on Boolean Values

#### 3.9.1 Example

not(true())

boolean n = ((XSBoolean)rs.first()).value(); println(n);

in order to get the result of ‘false’

### 3.10 Component Extraction Functions on Durations, Dates and Times

#### 3.10.1 Example

timezone-from-time(xs:time("13:20:00+05:00"))

String n = ((XDTDayTimeDuration)rs.first()).stringvalue(); println(n);

in order to get the result of ‘PT5H’

### 3.11 Functions Related to QNames

#### 3.11.1 Example

local-name-from-QName(QName(‘http://www.example.com/example’, ‘person’))

String n = ((XSNCName)rs.first()).stringvalue(); println(n);

in order to get the result of ‘person’

### 3.12 Functions on Nodes

### 3.13 General Functions on Sequences

#### 3.13.1 Example

remove((‘s’,‘o’,‘m’,‘e’,‘t’,‘h’,‘i’,‘n’,‘g’), 6)

for (Iterator iter = rs.iterator(); iter.hasNext();) { Object item = iter.next(); String n = ((XSString)item).stringvalue(); print(n + " "); } println("");

in order to get the result of ‘s o m e t i n g’

### 3.14 Functions That Test the Cardinality of Sequences

#### 3.14.1 Example

one-or-more((1,2,3,4,5))

for (Iterator iter = rs.iterator(); iter.hasNext();) { Object item = iter.next(); int n = ((XSInteger)item).intvalue(); print(n + " "); } println("");

in order to get the result of ‘1 2 3 4 5’

### 3.15 Deep-Equal, Aggregate Functions, and Functions that Generate Sequences

#### 3.15.1 Example

avg((3,4,5))

double avg = ((XSDouble)rs.first()).doublevalue(); println(avg);

in order to get the result of ‘4.0’

### 3.16 Context Functions

#### 3.16.1 Example

(10 to 20)[position() = 2]

int pos = ((XSInteger)rs.first()).intvalue(); println(pos);

in order to get the result of ‘11’

## 4 How to use XPath 2.0 operators with PsychoPath

The aim of this section is to give the user an overview of the available XPath 2.0 operators that are implemented in PsychoPath. For the formal specifications, see the W3C web-site for XPath 2.0 functions and operators<ref name="ftn4">http://www.w3.org/TR/xpath-functions/</ref>.

### 4.1 Operators on Numeric Values

#### 4.1.1 Example

xs:integer(4) + xs:integer(3)

integer n = ((XSInteger)rs.first()).integervalue(); println(n);

in order to get the result of ‘7’

### 4.2 Comparison of Numeric Values

#### 4.2.1 Example

xs:decimal(3.3) = xs:decimal(6.6)

boolean n = ((XSBoolean)rs.first()).value(); println(n);

in order to get the result of ‘false’

### 4.3 Operators on Boolean Values

#### 4.3.1 Example

xs:boolean(’true’) gt xs:boolean(’false’)

boolean n = ((XSBoolean)rs.first()).value(); println(n);

in order to get the result of ‘true’

### 4.4 Comparisons of Duration, Date and Time Values

#### 4.4.1 Example

xs:time("23:00:00+06:00") < xs:time("12:00:00-06:00")

boolean n = ((XSBoolean)rs.first()).value(); println(n);

in order to get the result of ‘true’

### 4.5 Arithmetic Functions on Durations

#### 4.5.1 Example

multiply-dayTimeDuration(xdt:dayTimeDuration("PT2H10M"), 2.1)

String n = ((XDTDayTimeDuration)rs.first()).stringvalue(); println(n);

which returns a xdt:dayTimeDuration value corresponding to 4 hours and 33 minutes ‘PT4H33M’

### 4.6 Arithmetic Functions Dates and Times

#### 4.6.1 Example

add-yearMonthDuration-to-dateTime( xs:dateTime("2000-10-30T11:12:00"), xdt:yearMonthDuration("P1Y2M"))

String n = ((XSDateTime)rs.first()).stringvalue(); println(n);

which returns an xs:dateTime value corresponding to the lexical representation ‘2001-12-30T11:12:00’

### 4.7 Operators Related to QNames And Nodes

#### 4.7.1 Example

xs:QName(’ao’) eq xs:QName(’ao’)

boolean n = ((XSBoolean)rs.first()).value(); println(n);

which returns the result of ‘true’

### 4.8 Union, Intersection and Except

#### 4.8.1 Example

union($seq2, $seq3)

for (Iterator iter = rs.iterator(); iter.hasNext();) { Object item = iter.next(); String n = ((XSString)item).stringvalue(); print(n + ", "); } println("");

which returns the sequence consisting of $item1, $item2, $item3.

### 4.9 Operators that Generate Sequences

#### 4.9.1 Example

(1 to 3)

int n = (XSInteger)rs.first()).stringvalue(); println(n);

which returns the sequence consisting of 1, 2, 3.

<references/>