XQuery 1.0: An XQL Query Language Attempt 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 ??
XQuery 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……
XQuery: 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….
Tree Representation of an XML Document, D Figure 1 from TIMBER: A native XML Database
The personnel of a department can be faculty, facultyid A Relational Schema staffidname 1J.Smith 2T.Brown 3K.Blue 4M.Black 5L.Young 6P.White 7H.Grey 8 9R.King
The personnel of a department can be faculty, lecturers, facultyid lecturersid 9 A Relational Schema staffidname 1J.Smith 2T.Brown 3K.Blue 4M.Black 5L.Young 6P.White 7H.Grey 8 9R.King
The personnel of a department can be faculty, lecturers, or scientists. facultyid lecturersid 9 scientistsid 5 A Relational Schema staffidname 1J.Smith 2T.Brown 3K.Blue 4M.Black 5L.Young 6P.White 7H.Grey 8 9R.King
staff idname 1J.Smith 2T.Brown 3K.Blue 4M.Black 5L.Young 6P.White 7H.Grey 8 9R.King facultyid lecturersid 9 scientistsid 5 They may or may not have a secretary. secretariessec_idboss_id A Relational Schema
facultyid lecturersid 9 scientistsid 5 tasnameboss_id Peter3 Bob3 Mark9 Andy9 Chris9 A lecturer can have TAs, no RAs. staffidname 1J.Smith 2T.Brown 3K.Blue 4M.Black 5L.Young 6P.White 7H.Grey 8 9R.King
facultyid lecturersid 9 scientistsid 5 rasnameboss_id Tom1 Pam3 DJ3 Tod5 Max5 Ann5 Lisa5 Jerry7 Tony7 Rich7 Grey7 A scientist can have RAs, but no TAs. staffidname 1J.Smith 2T.Brown 3K.Blue 4M.Black 5L.Young 6P.White 7H.Grey 8 9R.King
facultyid lecturersid 9 scientistsid 5 Each faculty may have both TAs and RAs. tasnameboss_id Peter3 Bob 3 Mark9 Andy9 Chris9 rasnameboss_id Tom1 Pam3 DJ3 Tod5 Max5 Ann5 Lisa5 Jerry7 Tony7 Rich7 Grey7 staffidname 1J.Smith 2T.Brown 3K.Blue 4M.Black 5L.Young 6P.White 7H.Grey 8 9R.King
z <!DOCTYPE department [ ]> The personnel of a department can be staff, faculty, lecturers, or scientists. Data Type Definition (DTD) for Amber XML document
The personnel of a department can be staff, faculty, lecturers, or scientists. ….. …. …. …. …. XML
z <!DOCTYPE department [ ]> Each of them has a name as identification. DTD
z <!DOCTYPE department [ ]> They may or may not have a secretary. DTD
They may or may not have a secretary. T.Brown K.Blue M.Black Each of them has a name as identification. XML
z <!DOCTYPE department [ ]> Each faculty may have both TAs and RAs. DTD
Each faculty may have both TAs and RAs. K.Blue M.Black Peter Bob Pam DJ XML
z <!DOCTYPE department [ ]> A lecturer can have one or more TAs, but no RA.. DTD
z <!DOCTYPE department [ ]> A scientist can have any number of RAs, but no TA. DTD
Bring up the Timber XML document in a web browser. In a separate browser, connect to the Timber 2 relational DB.
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 ] SQL SELECT Syntax
Querying Timber 2 relational DB with SQL See Relational DB Design #2 on handout (page ??) Write an SQL Query to: List the names of all faculty members. select staff.name from faculty, staff where faculty.id = staff.id Enter the query in the text box of the web page and click “Submit Query”
The XQuery FLWOR expression For-Let-Where-Order-Return pronounced "flower" generalizes SELECT-FROM-HAVING-WHERE from SQL
XQuery FLWOR See d.xml on handout pg ? or at 1. List the names of all faculty members. for $fac in doc(" return $fac/name K.Blue M.Black
XQuery FLWOR – Let’s Try one. See d.xml on handout pg ? or at List the names of all faculty members. for $faculty in doc(" return $faculty/name K.Blue M.Black 1. Web browse to: 2. Select XQuery Updates 1 from dropdown menu 3. Enter this XQuery expression in the left text box, then Submit Query.
XQuery FLWOR See d.xml on handout pg ? or at 2. List the names of all TAs working for faculty, (not for lecturers) for $fac in doc(" return $fac/name K.Blue M.Black Peter Bob Pam DJ Who can build this XQuery first? for $fac in doc(" return $fac/ta
XQuery FLWOR See d.xml on handout pg ? or at 3. List the names of all faculty members (without XML tags) for $fac in doc(" return $fac/name K.Blue M.Black Peter Bob Pam DJ for $fac in doc(" return data($fac/name)
XQuery FLWOR See d.xml on handout pg ? or at 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(" return {data($fac/name)} }
{ for $ra in doc(" order by data ( $ra) return {data($ra) } } 5. List the names of all RAs working for scientists (without XML tags) sorted alphabetically, in an ordered html list. { for $fac in doc(" return {data($fac/name)} } Who can solve first? L.Young P.White Todd Ann Lisa
for $sec in doc(" order by data( $sec) return data($sec) 6. List the secretary names (without XML tags or HTML tags) of all employees, sorted alphabetically Who can solve first? L.Young P.White Todd Ann Lisa { for $ra in doc(" order by data ( $ra) return {data($ra)} }
References