Javatpoint Logo
Javatpoint Logo

XQuery HTML Format

XQuery can also be used to transform an XML document into an HTML page.

Let's take an example to see how it works:


XQuery HTML Format Example

Let's take an XML file named "books.xml", having the following code.

XML statement:

books.xml:

XQuery Expression:

books.xqy:

This example will select all the title elements under the book elements that are under the bookstore element, and return the title elements in alphabetical order.

Now, create a Java based XQuery executor program to read the books.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 XQuery4. 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 Html format 1

If you want to eliminate the title element and show only the data inside the title element, use the following XQuery expression:

books.xqy:

Output:

XQUERY Html format 2
Next TopicXQuery XPath




Help Others, Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA