Basic XQuery concepts

W3C XQuery is a query language for XML.The most common use cases for XQuery involve XML publishingto create XML for Web messages, dynamic web sites, or publishing applications.

Most XQuery functionality, such as arithmetic operators, comparisons, function calls, and functions, is familiar to most programmers.The original data may be found in XML files, or it may be in a data store such as a relational.

XQuery are made up of three components:

1) Finding XML Nodes: Path Expressions


Just as SQL needs to be able to access any row or column in a relational table,
XQuery needs to be able to access any node in an XML document. XML structures have both hierarchy and sequence, and can contain complex structure.

2)Creating XML: XML Constructors
Now that we have seen how to locate anything in an XML document or a relational table,let's learn how to create new XML structures using XML constructors.

3) Restructuring Data: FLWOR Expressions
XQuery has an expression called a FLWOR expression,
which is similar to a SQL Select statement that that has From and Where clauses.
FLWOR is pronounced "flower", and is an acronym for the keywords used to introduce each clause
(for, let, where, order by, and return).

Sample Example :-
define function reverse($items){
let $count := count($items)
for $i in 0 to $count
return $items[$count - $i]

}