XQuery Tutorial – Overview

The XQuery Tutorial covers the topics on Xquery Functions, XQuery FLWOR, XQuery Syntax, XQuery Add, XQuery Select , extracting elements and attributes from XML documents, transform XML data to XHTML, XPath Operators , XPath Functions, XQuery Data Types, XQuery User-Defined Functions.

Lets discuss XQuery in detail.

What is XQuery?

The XML data includes the XML elements or called XML “nodes” which should be valid and could be parsed in a well formed XML Document. The XML data need to be queried like we use SQL Query to Query the Database data.

Thus , XQuery is designed to help in Querying the XML data.

XQuery – Points to Consider

  1. XQuery is W3C recommedation and XQuery Version 1.0 is recommendation by W3C in 2007.
  2. XQuery is compatible with XML, Namespaces, XSLT, XPath, and XML Schema
  3. XQuery is the language used for querying the XML data
  4. XQuery is built on the XPath expressions

How XQuery is useful ?

The XQuery can be used for the below given reasons :

  1. XQuery is compatible with XML, Namespaces, XSLT, XPath, and XML Schema
  2. XQuery helps in extracting the information in a heterogeneous environment integrated using XML
  3. XQuery is useful in transforming the XML data to XHTML
  4. helps in searching web documents for the related information.
  5. XQuery helps in generating reports
<oracleappshelpuser>
<student>
    <firstName>Mohit</firstName>
    <lastName>Sharma</lastName>
  	<registered>Yes<registered>
</student>
<student>
    <firstName>Rahul</firstName>
    <lastName>Jain</lastName>
  	<registered>Yes<registered>
</student>
<student>
    <firstName>Abhishek</firstName>
    <lastName>Gupta</lastName>
  	<registered>No<registered>
</student>
</oracleappshelpuser>

XQuery – Retrieve XML Node data from XML Document

XQuery provides the XQuery Functions which are used for extracting / retrieving the XML Data from the XML “nodes” in the XML Document.

Example:

doc(“student.xml”) is the XQuery function to open the Student.xml file for Query the XML Document.

We will discuss more in detail for the Query Functions in the next blog.

XQuery – Navigate using XPath expressions

XQuery uses the in built XPath expressions for navigating to the XMl node in the XML Document

Example: If we need to navigate to the firstName node in the above provided student.xml , then the below expression should be used

doc(“student.xml”)/oracleappshelpuser/student/firstName

The XQuery output should be like:

    <firstName>Mohit</firstName>
	<firstName>Rahul</firstName>
	<firstName>Abhishek</firstName>

We will discuss more in detail for the Query XPath expression in the next blog.