Explain xpath and xquery with simple words

I am new to programming. I know what XML is. Can someone explain in plain language what xpath and xquery do Where are they used?

+7
xquery xpath
source share
4 answers

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> 
+13
source share

XPath is a simple query language that searches XML DOM. I think it can be compared with SQL Select statements with databases. XPath can evaluate many programs that work with XML and are in widespread use. I recommend you study it.

XQuery is much more powerful and complex, it also offers many options for how to transform the result, offers loops, etc. But also a query language. It is also used as a query language in XML databases. I think that this language has only a specific use and probably it is not necessary to know it, in the beginning it will be enough if you know that it exists and that it can

There is a simple explanation, I hope this is clear enough

+5
source share

This XPATH tutorial is pretty simple and easy to use. Also check out the related XML and XQUERY tutorials .

-one
source share

I also suggest you take a look at this page in the following, which may help get some idea.

link text

-2
source share

All Articles