0% found this document useful (0 votes)
68 views11 pages

Unit3

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views11 pages

Unit3

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Web Data Management

Prof. Rinkal Sarvaiya, Assistant Professor


IT & Computer Science
Unit 3 - XQuery
What is XQuery?
• XQuery is a functional language that is used to retrieve information
stored in XML format.
• XQuery can be used on XML documents, relational databases containing data
in XML formats, or XML Databases.
• XQuery 3.0 is a W3C recommendation from April 8, 2014.
• The definition of XQuery as given by its official documentation is as follows:
XQuery is a standardized language for combining documents, databases,
Web pages and almost anything else.
• It is very widely implemented.
• It is powerful and easy to learn.
• XQuery is replacing proprietary middleware languages
and Web Application development languages.
• XQuery is replacing complex Java or C++ programs
with a few lines of code. XQuery is simpler to work
with and easier to maintain than many other
alternatives.
Characteristics

• Functional Language ─ XQuery is a language to retrieve/querying XML based


data.
• Analogous to SQL ─ XQuery is to XML what SQL is to databases.
• XPath based ─ XQuery uses XPath expressions to navigate through XML
documents.
• Universally accepted ─ XQuery is supported by all major databases.
• W3C Standard ─ XQuery is a W3C standard
Benefits of XQuery

• Using XQuery, both hierarchical and tabular data can be retrieved.


• XQuery can be used to query tree and graphical structures.
• XQuery can be directly used to query webpages.
• XQuery can be directly used to build webpages.
• XQuery can be used to transform xml documents.
• XQuery is ideal for XML-based databases and object-based databases. Object
databases are much more flexible and powerful than purely tabular databases.
Book.xml
Books.xqy
<?xml version="1.0" encoding="UTF-8"?>
<books> for $x in doc("books.xml")/books/book
<book category="JAVA"> where $x/price>30
<title lang="en">Learn Java in 24 Hours</title> return $x/title
<author>Robert</author>
<year>2005</year>
<price>30.00</price>
</book> Output
<book category="DOTNET">
<title lang="en">Learn .Net in 24 hours</title>
<title lang="en"> Learn Java in 24 Hours </title>
<author>Peter</author>
<title lang="en"> Learn .Net in 24 hours </title>
<year>2011</year>
<price>70.50</price>
</book>
XQuery ─ FLWOR

FLWOR is an acronym that stands for "For, Let, Where, Order by, Return".
The following list shows what they account for in a FLWOR expression:
 F - For - Selects a collection of all nodes.
 L - Let - Puts the result in an XQuery variable.
 W - Where - Selects the nodes specified by the condition.
 O - Order by - Orders the nodes specified as per criteria.
 R - Return - Returns the final result.
Example : We will use a FLWOR expression to retrieve the titles of those books with a price greater than 30.

Books.xml Books.xqy
<?xml version="1.0" encoding="UTF-8"?> let $books := (doc("books.xml")/books/book)
<books> return
<book category="JAVA"> {
<title lang="en">Learn Java in 24 Hours</title> for $x in $books
<author>Robert</author> where $x/price>30
<year>2005</year> order by $x/price
<price>30.00</price> return $x/title
</book> }
<book category="DOTNET">
<title lang="en">Learn .Net in 24 hours</title>
<author>Peter</author>
<year>2011</year>
<price>70.50</price>
</book>
Advance Expressions
• Except FLOWR others expression also there :
1) XQuery Conditional Expression :
"If-Then-Else" expressions are allowed in XQuery.
Example :

<adult>Dot Not
</adult>
for $x in doc("books.xml")/books/book <child>peter</
child>
return if ($x/@category=“java") <adult>Java</a
dult>
then <child>{data($x/title)}</child> <child>Robert<
/child>
else <adult>{data($x/title)}</adult>
XQuery Regular Expression

Index Name Description


1) matches($input, $regex) It returns true if the input matches with the provided
regular expression.
2) replace($input, $regex, It is used to replace the matched input string with
$string) given string.
3) tokenize($input, $regex) It is used to return a sequence of items matching the
regular expression.

You might also like