Javatpoint Logo
Javatpoint Logo

XQuery XPath

XQuery uses XPath expressions to restrict the search results on XML collections.


XQuery XPath Example

Let's take an XML document having the information on the collection of courses. We will use XQuery expression to retrieve the titles of those courses.

courses.xml

Here, we use three different types of XQuery statement that will display the same result having fees is greater than 2000.


XQuery Type 1

courses.xqy


How to run

Create a Java based XQuery executor program to read the courses.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 XQuery3. 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 Xpath 1

XQuery Type 2

Follow the same procedure specified above:

Output:

XQUERY Xpath 2

XQuery Type 3

Follow the same procedure specified above:

Output:

XQUERY Xpath 3
Next TopicXQuery Syntax




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


B.Tech / MCA