Download presentation
Presentation is loading. Please wait.
Published byRalf Burke Modified over 8 years ago
1
XQuery 1.0: An XQL Query Language http://www.mcsr.olemiss.edu/ppt/XQuery.ppt 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 ??
2
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……
3
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…. http://www.w3.org/XML/Query/
4
Tree Representation of an XML Document, D Figure 1 from TIMBER: A native XML Database
5
The personnel of a department can be faculty, facultyid 1 3 7 A Relational Schema staffidname 1J.Smith 2T.Brown 3K.Blue 4M.Black 5L.Young 6P.White 7H.Grey 8 9R.King
6
The personnel of a department can be faculty, lecturers, facultyid 1 3 7 lecturersid 9 A Relational Schema staffidname 1J.Smith 2T.Brown 3K.Blue 4M.Black 5L.Young 6P.White 7H.Grey 8 9R.King
7
The personnel of a department can be faculty, lecturers, or scientists. facultyid 1 3 7 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
8
staff idname 1J.Smith 2T.Brown 3K.Blue 4M.Black 5L.Young 6P.White 7H.Grey 8 9R.King facultyid 1 3 7 lecturersid 9 scientistsid 5 They may or may not have a secretary. secretariessec_idboss_id 43 65 87 A Relational Schema
9
facultyid 1 3 7 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
10
facultyid 1 3 7 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
11
facultyid 1 3 7 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
12
z <!DOCTYPE department [ ]> The personnel of a department can be staff, faculty, lecturers, or scientists. Data Type Definition (DTD) for Amber XML document
13
The personnel of a department can be staff, faculty, lecturers, or scientists. ….. …. …. …. …. XML
14
z <!DOCTYPE department [ ]> Each of them has a name as identification. DTD
15
z <!DOCTYPE department [ ]> They may or may not have a secretary. DTD
16
They may or may not have a secretary. T.Brown K.Blue M.Black Each of them has a name as identification. XML
17
z <!DOCTYPE department [ ]> Each faculty may have both TAs and RAs. DTD
18
Each faculty may have both TAs and RAs. K.Blue M.Black Peter Bob Pam DJ XML
19
z <!DOCTYPE department [ ]> A lecturer can have one or more TAs, but no RA.. DTD
20
z <!DOCTYPE department [ ]> A scientist can have any number of RAs, but no TA. DTD
21
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
22
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
23
Querying 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 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”
24
The 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
25
XQuery FLWOR See d.xml on handout pg ? or at http://www.mcsr.olemiss.edu/d.xml 1. List the names of all faculty members. for $fac in doc("http://www.mcsr.olemiss.edu/d.xml")//faculty return $fac/name K.Blue M.Black
26
XQuery FLWOR – Let’s Try one. See d.xml on handout pg ? or at http://www.mcsr.olemiss.edu/d.xml List the names of all faculty members. for $faculty in doc("http://www.mcsr.olemiss.edu/d.xml")//faculty return $faculty/name K.Blue M.Black 1. Web browse to: http://support.x-hive.com/xquery/ 2. Select XQuery Updates 1 from dropdown menu 3. Enter this XQuery expression in the left text box, then Submit Query.
27
XQuery FLWOR See d.xml on handout pg ? or at http://www.mcsr.olemiss.edu/d.xml 2. List the names of all TAs working for faculty, (not for lecturers) for $fac in doc("http://www.mcsr.olemiss.edu/d.xml")//faculty return $fac/name K.Blue M.Black Peter Bob Pam DJ Who can build this XQuery first? for $fac in doc("http://www.mcsr.olemiss.edu/d.xml")//faculty return $fac/ta
28
XQuery FLWOR See d.xml on handout pg ? or at http://www.mcsr.olemiss.edu/d.xml 3. List the names of all faculty members (without XML tags) for $fac in doc("http://www.mcsr.olemiss.edu/d.xml")//faculty return $fac/name K.Blue M.Black Peter Bob Pam DJ for $fac in doc("http://www.mcsr.olemiss.edu/d.xml")//faculty return data($fac/name)
29
XQuery 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")//faculty return {data($fac/name)} }
30
{ for $ra in doc("http://www.mcsr.olemiss.edu/d.xml")//scientist/ra 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("http://www.mcsr.olemiss.edu/d.xml")//faculty return {data($fac/name)} } Who can solve first? L.Young P.White Todd Ann Lisa
31
for $sec in doc("http://www.mcsr.olemiss.edu/d.xml")//*/secretary 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("http://www.mcsr.olemiss.edu/d.xml")//scientist/ra order by data ( $ra) return {data($ra)} }
32
References http://www.w3.org/TR/xquery/ http://xmlbeans.apache.org/ http://www.stylusstudio.com/xquery_primer.html http://www.w3schools.com/xquery/xquery_flwor_html.asp http://www.brics.dk/~amoeller/XML/querying/flwrexp.html http://www.xmlfiles.com/dtd/dtd_elements.asp http://support.x-hive.com/xquery/ http://www.saxonica.com/documentation/javadoc/index.html http://www.stylusstudio.com/xquery_primer.html http://www.oracle.com/technology/tech/xml/xquery/index.html
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.