- An expression language to be used in another host language (e.g., XSLT, XQuery).
- Moreover, Allows the description of paths in an XML tree, and the retrieval of nodes that match these paths.
- So, Can also be used for performing some (limited) operations on XML data.
2*3 is an XPath literal expression. //*[ @msg=”Hello world” ] is an XPath path expression, retrieving all elements with an msg attribute set to “Hello world”.
XPath Data Model
it expressions operate over XML trees, which consist of the following node types:
- Document: the root node of the XML document;
- Element: element nodes;
- Attribute: attribute nodes, represented as children of an Element node;
- Text: text nodes, i.e., leaves of the XML tree.
An axis = a set of nodes determined from the context node. And Also, an ordering of the sequence.
- child: (default axis).
- parent: Parent node.
- attribute: Attribute nodes.
- descendant: Descendants, excluding the node itself.
- descendant-or-self: Descendants, including the node itself.
- ancestor: Ancestors, excluding the node itself.
- ancestor-or-self: Ancestors, including the node itself.
- following: Following nodes in document order.
- following-sibling: Following siblings in document order.
- preceding: Preceding nodes in document order.
- preceding-sibling: Preceding siblings in document order.
- self: The context node itself.
- XQuery is an XML query language that makes use of XPath to query XML structures.
- However, it also allows for functions to be defined and called, as well as complex querying of data structures using FLWOR
- FLWOR allows for join functionality between data sets defined in XML.
Also, FLWOR article from Wikipedia Sample XQuery (using some XPath) is:
declare function local:toggle-boolean($b as xs:string)
if ($b = “Yes”) then “true”
else if ($b = “No”) then “false”
lse if ($b = “true”) then “Yes”
else if ($b = “false”) then “No”
else “[ERROR] @ local:toggle-boolean”