XQuery Sequences

XQuery sequences are used to specify an ordered collection of items. These items can be of similar or different types.


Creating a sequence

An XQuery sequence is created using parenthesis with strings inside quotes or double quotes or numbers. XML elements can also be used as the items of a sequence.

There are two ways to create items of sequence iterated one by one.

  • Using index
  • Using values

XQuery Expression for Index

items.xqy

How to run

Create a Java based XQuery executor program to read the items.xqy, passes it to the XQuery expression processor, and executes the expression. After that the result will be displayed.

XQueryTester.java


Execute XQuery against XML

Put the above three files to a same location. We put them on desktop in a folder name XQuery7. Compile XQueryTester.java using console. You must have JDK 1.5 or later installed on your computer and classpaths are configured.

Compile:

javac XQueryTester.java

Execute:

java XQueryTester

Output:

XQUERY Sequence 1

XQuery Expression for Index

items.xqy

Follow the same procedure as above:

Output:

XQUERY Sequence 2



Latest Courses