Title: XQuery 1.0: An XQL Query Language
 1XQuery 1.0 An XQL Query Language
http//www.mcsr.olemiss.edu/ppt/XQuery.ppt Attemp
t by W3C at a standard query language for 
XML.Has been called the SQL for XML W3C 
Candidate Recommendation (3 November 2005) 
 Current Status Waiting for implementations. ..
. Next W3C Proposed Recommendation ?? 
 2XQuery 1.0 Miscellany
What Came Before? XQL XML Query 
Language XML-QL A Query Language for XML XPath 
XML Path Language (W3C 1999) Related 
Technologies XSLT XML Stylesheet Language 
Transformations (W3C 1999) XPointer XML Pointer 
Language (W3C 2001) XMLBeans a technology for 
accessing XML  by binding it to Java types A 
bunch of other stuff XStuff 
 3XQuery Early Implementations
Commercial Implementations Relational XQuery  
Abacus Systems. 30 day trial. XMLSpy 2005 
Altova. 30 day trial. XHive/DB X-Hive. 
Commercial. Web demo.Oracle SQL Server Open 
Source Implementations Galax Open Source Mono 
Project Open Source XMLBeans a technology for 
accessing XML  by binding it to Java types 
 More implementations. http//www.w3.org/XML/Que
ry/ 
 4Tree Representation of an XML Document, D Figure 
1 from TIMBER A native XML Database 
 5The personnel of a department can be faculty,
A Relational Schema 
 6The personnel of a department can be faculty, 
lecturers,
A Relational Schema 
 7The personnel of a department can be faculty, 
lecturers, or scientists.
A Relational Schema 
 8They may or may not have a secretary.
A Relational Schema 
 9A lecturer can have TAs, no RAs. 
 10A scientist can have RAs, but no TAs. 
 11Each faculty may have both TAs and RAs. 
 12Data Type Definition (DTD) for Amber XML document
z department   faculty  lecturer  scientist)) staff ( name, (secretary?) ) faculty (name, secretary?, ta, ra)   
 (PCDATA)  
The personnel of a department can be staff, 
faculty, lecturers, or scientists. 
 13XML
  .. 
 . 
.  .artment
The personnel of a department can be staff, 
faculty, lecturers, or scientists. 
 14DTD
z department   faculty  lecturer  scientist)) staff ( name, (secretary?) ) faculty (name, secretary?, ta, ra)   
 (PCDATA)  
Each of them has a name as identification. 
 15DTD
z department   faculty  lecturer  scientist)) staff ( name, (secretary?) ) faculty (name, secretary?, ta, ra)   
 (PCDATA)  
They may or may not have a secretary. 
 16XML
  T.Brown 
Each of them has a name as identification.
 K.Blue 
M.Black
They may or may not have a secretary. 
 17DTD
z department   faculty  lecturer  scientist)) staff ( name, (secretary?) ) faculty (name, secretary?, ta, ra)   
 (PCDATA)  
Each faculty may have both TAs and RAs. 
 18XML
 K.Blue  
M.Black  
Peter  Bob  
Pam DJ  
Each faculty may have both TAs and RAs. 
 19DTD
z department   faculty  lecturer  scientist)) staff ( name, (secretary?) ) faculty (name, secretary?, ta, ra)   
 (PCDATA)  
A lecturer can have one or more TAs, but no RA.. 
 20DTD
z department   faculty  lecturer  scientist)) staff ( name, (secretary?) ) faculty (name, secretary?, ta, ra)   
 (PCDATA)  
A scientist can have any number of RAs, but no 
TA. 
 21http//willow.olemiss.edu/engr654/timber2.php
Bring up the Timber XML document in a web 
browser. http//www.mcsr.olemiss.edu/d.xml
In a separate browser, connect to the Timber 2 
relational DB.
http//willow.olemiss.edu/engr654/timber2.php 
 22SQL SELECT Syntax
SELECT  DISTINCT  ALL  column_expression1, 
column_expression2, ....  FROM from_clause   
WHERE where_expression  GROUP BY expression1, 
expression2, ....  HAVING having_expression 
 ORDER BY order_column_expr1, 
order_column_expr2, ....  column_expression 
 expression  AS   column_alias  
 from_clause  select_table1, select_table2, 
... from_clause  select_table1 LEFT OUTER 
JOIN select_table2 ON expr ... from_clause  
select_table1 RIGHT OUTER JOIN select_table2 ON 
expr ... from_clause  select_table1 INNER 
JOIN select_table2 ...  select_table  
table_name  AS   table_alias  select_table 
 ( sub_select_statement )  AS   table_alias 
 order_column_expr  expression  ASC  DESC  
 23Querying Timber 2 relational DB with 
SQL http//willow.olemiss.edu/engr654/timber2.php
See Relational DB Design 2 on handout (page ??)
Write an SQL Query toList the names of all 
faculty members.
select staff.name from faculty, staffwhere 
faculty.id  staff.id
Enter the query in the text box of the web 
pageand click Submit Query 
 24The XQuery FLWOR expression 
For-Let-Where-Order-Return pronounced "flower" 
 generalizes SELECT-FROM-HAVING-WHERE from SQL 
http//www.brics.dk/amoeller/XML/querying/flwrexp
.html 
 25XQuery FLWOR  
See d.xml on handout pg ? or at 
http//www.mcsr.olemiss.edu/d.xml 
1. List the names of all faculty members.
 K.Blue 
M.Black
for fac in doc("http//www.mcsr.olemiss.edu/d.xm
l")//faculty
return fac/name 
 26XQuery FLWOR  Lets Try one. 
See d.xml on handout pg ? or at 
http//www.mcsr.olemiss.edu/d.xml 
1. Web browse to http//support.x-hive.com/xquer
y/
List the names of all faculty members.
2. Select XQuery Updates 1 from dropdown menu
 K.Blue 
M.Black
3. Enter this XQuery expression in theleft text 
box, then Submit Query. 
for faculty in doc("http//www.mcsr.olemiss.edu/
d.xml")//faculty
return faculty/name 
 27XQuery FLWOR  
See d.xml on handout pg ? or at 
http//www.mcsr.olemiss.edu/d.xml 
for fac in doc("http//www.mcsr.olemiss.edu/d.xm
l")//faculty
return fac/name
 K.Blue  
M.Black  
Peter  Bob  
Pam DJ  
2. List the names of all TAs working for 
faculty, (not for lecturers)
Who can build this XQuery first?
for fac in doc("http//www.mcsr.olemiss.edu/d.xm
l")//facultyreturn fac/ta 
 28XQuery FLWOR  
See d.xml on handout pg ? or at 
http//www.mcsr.olemiss.edu/d.xml 
for fac in doc("http//www.mcsr.olemiss.edu/d.xm
l")//faculty
return fac/name
 K.Blue  
M.Black  
Peter  Bob  
Pam DJ  
3. List the names of all faculty members 
(without XML tags)
for fac in doc("http//www.mcsr.olemiss.edu/d.xm
l")//facultyreturn data(fac/name) 
 29XQuery FLWOR  
See d.xml on handout pg ? or at 
http//www.mcsr.olemiss.edu/d.xml 
4. List the names of all faculty members 
(without tags)in an unordered list
 K.Blue  
M.Black  
Peter  Bob  
Pam DJ  
  for fac in doc("http//www.mcsr.olemiss.
edu/d.xml")//facultyreturn - data(fac/name)/li 
 
  30  for fac in doc("http//www.mcsr.olemiss.
edu/d.xml")//facultyreturn - data(fac/name)/li 
 
 5. List the names of all RAs working for 
scientists (without XML tags)sorted 
alphabetically,in an ordered html list.
 L.Young 
P.White 
Todd Ann 
Lisa 
Who can solve first?
  for ra in doc("http//www.mcsr.olemiss.e
du/d.xml")//scientist/raorder by data ( 
ra) return - data(ra) 
  
  31  for ra in doc("http//www.mcsr.olemiss.e
du/d.xml")//scientist/raorder by data ( 
ra) return - data(ra)
  
  L.Young 
P.White 
Todd Ann 
Lisa 
6. List the secretary names (without XML tags or 
HTML tags) of all employees,sorted alphabetically
Who can solve first?
for sec in doc("http//www.mcsr.olemiss.edu/d.xm
l")///secretaryorder by data( sec) return 
data(sec) 
 32References
http//www.w3.org/TR/xquery/ http//xmlbeans.apach
e.org/ http//www.stylusstudio.com/xquery_primer.h
tml http//www.w3schools.com/xquery/xquery_flwor_h
tml.asp http//www.brics.dk/amoeller/XML/querying
/flwrexp.html http//www.xmlfiles.com/dtd/dtd_elem
ents.asp http//support.x-hive.com/xquery/ http//
www.saxonica.com/documentation/javadoc/index.html 
http//www.stylusstudio.com/xquery_primer.html htt
p//www.oracle.com/technology/tech/xml/xquery/inde
x.html