Home / Interview / XQuery :: General Questions

Interview :: XQuery


What is XQuery?

XQuery is a case-sensitive XML query language which was designed to query XML data. It is same like SQL for database tables. XQuery is used to retrieve data from the XML file.

Example: Suppose we have to find out the list of students who situated in a particular area in an XML file. XQuery can solve these type of queries.

2) What is the use of XQuery language?

XQuery is a functional language for finding and extracting elements and attributes from XML documents. Some usage of the XQuery language is as follows:

  • To retrieve both hierarchal and tabular data.
  • To query both tree and graphical structures.
  • To build web pages.
  • To query web pages.
  • To transform XML documents into XHTML documents.
  • Best for XML-based databases and object-based databases. Object databases are much more flexible and powerful than purely tabular databases.
3) In which year XQuery first appeared?

XQuery was first appeared in 2007. It was designed by W3C and became the W3C recommendation on January 23, 2007. XQuery 3.0 is a W3C recommendation from April 8, 2014.

4) Explain the syntax rules for XQuery.

A list of basic syntax rules for XQuery:

  • XQuery is case sensitive.
  • Attributes and variables that we used should have valid XML names in XQuery elements.
  • XQuery should be written within single and double quotes.
  • XQuery variables should be defined as $(variable name). For example: $book.
  • XQuery comment can be written between colon (:). Like :(: Comment in XQuery:)

What is the difference between XQuery and XPath?

Difference between XQuery and XPath:

  • XQuery is the functional programming and query language while XPath is XML path language.
  • XQuery is used to extract and manipulate data from either XML documents or relational databases while XPath is used to compute values like strings, numbers and Boolean types from another XML documents.


What is the difference between XQuery and XSLT?

  • XQuery is program driven while XSLT is document-driven.
  • XQuery is declarative while XSLT is functional.
  • XSLT is written in XML while XQuery is not written in XML.
7) How to define functions in XQuery?

XML has many built-in functions. XQuery functions generally made perform with string values, numeric values, date and time comparisons, Boolean values.

XQuery also facilitates you to make your functions.

8) How to call XQuery functions:

Example 1: When you use function in an element.

Example 2: When you use function in the predicate of a path expression.

Example 3: When you use function in a let clause

9) How to perform the comparison in XQuery?

In XQuery, a comparison is performed with the general comparison or value comparison.

1. General Comparison: It is achieved by using the following symbols.

Ex: =, !=, <, <=, >, >=

2. Value Comparison: The value comparison is performed by using the following symbols.

Ex: ne, lt, le, eq, ge, gt.

See this example:

If any q attributes have values higher than 100, the expression returns true otherwise false.

10) What type of queries can the XQuery solve?

XQuery can be used to solve the following queries in XML data:

  • XQuery is used to retrieve information in a web service.
  • It is used to generate the summary report.
  • It is used to transform data from XML to XHTML.
  • It can be used when we want some relevant information from Web documents.