XPath and XQuery¶
Use this section when process logic or forms need XML navigation, XML querying, or XML updates beyond simple field binding.
XPath¶
Use XPath when you need to select values or nodes from the current XML structure. This is the most common choice for widget bindings, route conditions, validations, and lightweight expressions.
XPath treats XML as a tree of nodes and provides functions for strings, numbers, booleans, dates, and sequence operations. In practice, process builders use it to read or compare values rather than to reshape large XML documents.
XQuery¶
Use XQuery when XPath alone is not enough and you need richer querying, iteration, or XML update logic. XQuery builds on XPath, so understanding XPath first is strongly recommended.
XQuery grounds on the five expressions whose acronym is FLWOR (pronounced "flower").
- For selects a sequence of nodes
- Let binds a sequence to a variable
- Where filters the nodes
- Order by sorts the nodes
- Return defines what should be returned
With these expressions, you can query and shape XML data more expressively than with a single XPath statement.
Besides the main features of XQuery there is an extension called XQuery Update Facility which introduces some useful features to XQuery.
The XQuery Update Facility is a relatively small extension of the XQuery language which provides convenient means of modifying XML documents or data. As of March 14, 2008, the XQuery Update Facility specification has become a "Candidate Recommendation", which means it is now pretty stable.
Why an update facility in XML Query ? The answer seems obvious, yet after all the XQuery language itself - or its cousin XSLT2 - is powerful enough to write any transformation of an XML tree. Therefore a simple "store" or "put" function, applied to the result of such transformation, could seem sufficient to achieve any kind of database update operation. Well, perhaps. In practice this would be neither very natural, convenient, nor very efficient (such an approach requires storing back the whole document and makes optimizing very difficult). So as we will see the little complexity added by XQuery Update seems quite worth the effort.
How to Use This Section¶
- Start with XPath if you mainly need selections, comparisons, or function calls.
- Move to XQuery if you need iteration, transformation, or XML update workflows.
- Use XPath Functions as the quick reference once you already know the basics.