Here, is given XQuery interview questions and answers that have been asked in many companies. Let's see the list of top XQuery interview questions.
1) 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.
For more information: http://www.javatpoint.com/what-is-xquery
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:)
5) 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.
For more information: http://www.javatpoint.com/difference-between-xquery-and-xpath
6) 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.
For more information: http://www.javatpoint.com/xquery-vs-xslt
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.
11) What do you mean by XQuery FLWOR?
FLWOR is an acronym which stands for "For, Let, Where, Order by, Return."
For - It is used to select a sequence of nodes.
Let - It is used to bind a sequence to a variable.
Where - It is used to filter the nodes.
Order by - It is used to sort the nodes.
Return - It is used to specify what to return (gets evaluated once for every node).
For more information: http://www.javatpoint.com/xquery-flwor
12) What is the use of XQuery HTML format?
XQuery HTML format is a way to transform an XML document into an HTML page. For more information: http://www.javatpoint.com/xquery-html-format
13) What is selecting and filtering element in XQuery?
Selecting and filtering refer to query to the database for selecting a group of data and filtering that data for a specific type. For example to select the name of books whose price is less than 30 dollars? XQuery FLWOR and Path expression are used for selecting and filtering the XML elements. Both are used to select and filter the desired elements.
For example:
14) How to perform conditional operations in XQuery?
Conditional operation in XQuery is If-Then-Else operation. Let?s take an example to see how to use it:
Example:
15) What is the syntax of XQuery language?
The elements, attributes and variables in XQuery language must be valid XML names and follow case sensitivity. For more information: http://www.javatpoint.com/xquery-syntax
16) What do you mean by XQuery add?
XQuery add is used for adding elements, attributes, HTML elements and text in the results from the input documents.
For more information: http://www.javatpoint.com/xquery-add
17) How to use XQuery FLWOR with HTML?
If you want to put HTML element with XQuery FLWOR, you should have to add and tags into the FLWOR expression.
For example:
18) What are the different types of XQuery functions?
A list of different types of XQuery functions:
- Accessor Functions
- Error and Trace Functions
- Numeric Functions
- String Functions
- AnyURI Functions
- Boolean Functions
- Duration/Date/Time Functions
- QName Functions
- Node Functions
- Sequence Functions
- Context Functions
19) What are the uses of time and date function in XQuery?
In XQuery, time and date function are used to get time and date. There are three types of time and date functions in XQuery:
- current-date()
- current-time()
- current-datetime()
20) What is the use of current-date() function in XQuery?
The XQuery current date function is used to retrieve the current date.
21) What is the use of current-time() function in XQuery?
The XQuery current-time function is used to retrieve the current time.
For more information: http://www.javatpoint.com/xquery-current-time-function
22) What is the use of current-datetime() function in XQuery?
The XQuery current-date time() function is used to return the current date and time.
For more information: http://www.javatpoint.com/xquery-current-datetime-function
23) What is the difference between XPath expressions and FLWOR expressions in XQuery?
Path and FLWOR both can be used to query the XML file but differently. In XPath expression, we can specify the node which should be selected from the XML document along with a condition which should be filled to fetch the XML document. A condition can be of any type, for example, if we want to display the names of the books whose price is less than thirty dollars. Such condition can be applied to XPath expressions.
Whereas in FLWOR expression as the name suggests 'F' 'L' 'W' 'O' 'R' refers to 'for' 'let' 'Where' 'Order by' 'Return.' Where Return is compulsory and the rest of the elements such as 'for' 'let' 'where' 'order by' are optional.
24) What is meant by the word ?node? in XQuery?
Every element inside the XML document is treated as a node.
25) How many kinds of nodes are there in XQuery?
There were mainly seven kinds of nodes available in the XQuery listed below:
- Element
- Attribute
- Text
- Namespace
- Processing-instruction
- Comment
- Document (root) node.
26) What do you mean by atomic values in XQuery?
Atomic values refer to the nodes with no parent and children.
27) Explain the relationship of different nodes in XQuery?
Parent: Each element and attribute has one parent node.
Children: Elements node may have zero, one or multiple children.
Siblings: Siblings refers to the nodes which have the same parent node.
Ancestors: A node's parent's parent' parents... etc.
Descendants: A node's children's children's .... Etc.
28) Write the syntax of XQuery to select books only having the price less than 30 dollars.
doc("books123.xml")/bookstore/book[price<30]
29) Write a syntax to demonstrate the use of FLWOR expression in XQuery.
for $x in doc("books123.xml")/bookshop/book
where $x/price>60
order by $x/category
return $x/category
30) What is meant by for clause in XQuery?
For clause is used inside the FLWOR expression to bind a variable to each item returned by the expression. There can be one or more 'for' clause in the same expression.
31) What is meant by the order by clause in XQuery?
Order by clause is used inside the FLWOR expression to arrange the returned value by the FLWOR expression either in ascending order or in descending order or alphabetically. Order by clause is optional in FLWOR.
32) Which clause is compulsory in XQuery and why?
Return clause is mandatory to be added in the FLWOR expression because the primary objective of the query is to select some data.
No comments:
Post a Comment