Home » XML Basics » 05 - X Marks the Spot
5

Xquery

XQuery, the 'query language' for XML files will be discussed in this section.

XQuery is the query language for XML files. If you are familiar with databases then XQuery is to XML what SQL is to databases. SQL or structured query language is used to navigate through databases. XQuery is used to navigate through XML. Since you are familiar with XPath commands, using XQuery is simply secondary. Take a look at the XML code below.


<?xml version = "1.0"?> 

<classcard dategiven = "9/27/05" xmlns:xlink = "http://www.w3.org/1999/xlink" >

<name> Sara </name>
<subject> programming </subject>
<result> <grade> 3.5/4.0 </grade> very industrious and recites a lot </result>
<complaints xlink:href = "http://www.mcdonalds.com">
Eats McDonald’s in the middle of class
</complaints>

<name> Michael </name>
<subject> programming </subject>
<result> <grade> 3.0/4.0 </grade> does well on written exams but does not recite </result>
<complaints>
</complaints>

</classcard>

Using XQuery, "classcard/name" will return the values Sara and Michael.