XPath is a way of finding specific elements in an XML tree.
For example, given the following structure:
<myfarm> <animal type="dog"> <name>Fido</name> <color>Black</color> </animal> <animal type="cat"> <name>Mitsy</name> <color>Orange</color> </animal> </myfarm>
XPath allows you to navigate through a structure, for example:
/myfarm/animal[@type="dog"]/name/text()
which will give you "fido"
XQuery is an XML query language that uses XPath to query XML structures. However, it also allows you to define and invoke functions, as well as complex query data structures using FLWOR expressions . FLWOR allows you to combine functions between datasets defined in XML. FLWOR Wikipedia article
XQuery example (using some XPath):
declare function local:toggle-boolean($b as xs:string) as xs:string { if ($b = "Yes") then "true" else if ($b = "No") then "false" else if ($b = "true") then "Yes" else if ($b = "false") then "No" else "[ERROR] @ local:toggle-boolean" }; <ResultXML> <ChangeTrue>{ local:toggle-boolean(doc("file.xml")/article[@id="1"]/text()) }</ChangeTrue> <ChangeNo>{ local:toggle-boolean(doc("file.xml")/article[@id="2"]/text()) }</ChangeNo> </ResultXML>
John nickerson
source share