320 likes | 512 Views
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 . ...
E N D
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 ??
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…. http://www.w3.org/XML/Query/
Tree Representation of an XML Document, D Figure 1 from TIMBER: A native XML Database
The personnel of a department can be faculty, A Relational Schema
The personnel of a department can be faculty, lecturers, A Relational Schema
The personnel of a department can be faculty, lecturers, or scientists. A Relational Schema
They may or may not have a secretary. A Relational Schema
Data Type Definition (DTD) for Amber XML document <?xml version="1.0" encoding="UTF-8"?>z <!DOCTYPE department [ <!ELEMENT department ( (staff | faculty | lecturer | scientist)+)> <!ELEMENT staff ( name, (secretary?) )> <!ELEMENT faculty (name, secretary?, ta*, ra*)> <!ELEMENT lecturer (name, secretary?, ta*)> <!ELEMENT scientist (name, secretary?, ra*)> <!ELEMENT secretary ( - PCDATA)> <!ELEMENT ta (#PCDATA)> <!ELEMENT ra (#PCDATA)> <!ELEMENT name (#PCDATA)> ]> The personnel of a department can be staff, faculty, lecturers, or scientists.
XML <department> <staff> ….. </staff> <faculty> ….</faculty> <lecturer> ….</lecturer> <scientist> ….</scientist></department> The personnel of a department can be staff, faculty, lecturers, or scientists.
DTD <?xml version="1.0" encoding="UTF-8"?>z <!DOCTYPE department [ <!ELEMENT department ( (staff | faculty | lecturer | scientist)+)> <!ELEMENT staff ( name, (secretary?) )> <!ELEMENT faculty (name, secretary?, ta*, ra*)> <!ELEMENT lecturer (name, secretary?, ta*)> <!ELEMENT scientist (name, secretary?, ra*)> <!ELEMENT secretary ( - PCDATA)> <!ELEMENT ta (#PCDATA)> <!ELEMENT ra (#PCDATA)> <!ELEMENT name (#PCDATA)> ]> Each of them has a name as identification.
DTD <?xml version="1.0" encoding="UTF-8"?>z <!DOCTYPE department [ <!ELEMENT department ( (staff | faculty | lecturer | scientist)+)> <!ELEMENT staff ( name, (secretary?) )> <!ELEMENT faculty (name, secretary?, ta*, ra*)> <!ELEMENT lecturer (name, secretary?, ta*)> <!ELEMENT scientist (name, secretary?, ra*)> <!ELEMENT secretary ( - PCDATA)> <!ELEMENT ta (#PCDATA)> <!ELEMENT ra (#PCDATA)> <!ELEMENT name (#PCDATA)> ]> They may or may not have a secretary.
XML <staff> <name>T.Brown</name> </staff> Each of them has a name as identification. <faculty> <name>K.Blue</name> <secretary>M.Black</secretary></faculty> They may or may not have a secretary.
DTD <?xml version="1.0" encoding="UTF-8"?>z <!DOCTYPE department [ <!ELEMENT department ( (staff | faculty | lecturer | scientist)+)> <!ELEMENT staff ( name, (secretary?) )> <!ELEMENT faculty (name, secretary?, ta*, ra*)> <!ELEMENT lecturer (name, secretary?, ta*)> <!ELEMENT scientist (name, secretary?, ra*)> <!ELEMENT secretary ( - PCDATA)> <!ELEMENT ta (#PCDATA)> <!ELEMENT ra (#PCDATA)> <!ELEMENT name (#PCDATA)> ]> Each faculty may have both TAs and RAs.
XML <faculty> <name>K.Blue</name> <secretary>M.Black</secretary> <ta>Peter</ta> <ta>Bob</ta> <ra>Pam</ra> <ra>DJ</ra> </faculty> Each faculty may have both TAs and RAs.
DTD <?xml version="1.0" encoding="UTF-8"?>z <!DOCTYPE department [ <!ELEMENT department ( (staff | faculty | lecturer | scientist)+)> <!ELEMENT staff ( name, (secretary?) )> <!ELEMENT faculty (name, secretary?, ta*, ra*)> <!ELEMENT lecturer (name, secretary?, ta*)> <!ELEMENT scientist (name, secretary?, ra*)> <!ELEMENT secretary ( - PCDATA)> <!ELEMENT ta (#PCDATA)> <!ELEMENT ra (#PCDATA)> <!ELEMENT name (#PCDATA)> ]> A lecturer can have one or more TAs, but no RA..
DTD <?xml version="1.0" encoding="UTF-8"?>z <!DOCTYPE department [ <!ELEMENT department ( (staff | faculty | lecturer | scientist)+)> <!ELEMENT staff ( name, (secretary?) )> <!ELEMENT faculty (name, secretary?, ta*, ra*)> <!ELEMENT lecturer (name, secretary?, ta*)> <!ELEMENT scientist (name, secretary?, ra*)> <!ELEMENT secretary ( - PCDATA)> <!ELEMENT ta (#PCDATA)> <!ELEMENT ra (#PCDATA)> <!ELEMENT name (#PCDATA)> ]> A scientist can have any number of RAs, but no TA.
http://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
SQL 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 ]
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, staffwhere faculty.id = staff.id Enter the query in the text box of the web pageand click “Submit Query”
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
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. <faculty> <name>K.Blue</name> <secretary>M.Black</secretary></faculty> for$facin doc("http://www.mcsr.olemiss.edu/d.xml")//faculty return$fac/name
XQuery FLWOR – Let’s 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/xquery/ List the names of all faculty members. 2. Select XQuery Updates 1 from dropdown menu <faculty> <name>K.Blue</name> <secretary>M.Black</secretary></faculty> 3. Enter this XQuery expression in theleft text box, then Submit Query. for$facultyin doc("http://www.mcsr.olemiss.edu/d.xml")//faculty return$faculty/name
XQuery FLWOR See d.xml on handout pg ? or at http://www.mcsr.olemiss.edu/d.xml for$facin doc("http://www.mcsr.olemiss.edu/d.xml")//faculty return$fac/name <faculty> <name>K.Blue</name> <secretary>M.Black</secretary> <ta>Peter</ta> <ta>Bob</ta> <ra>Pam</ra> <ra>DJ</ra> </faculty> 2. List the names of all TAs working for faculty, (not for lecturers) Who can build this XQuery first? for$facin doc("http://www.mcsr.olemiss.edu/d.xml")//facultyreturn $fac/ta
XQuery FLWOR See d.xml on handout pg ? or at http://www.mcsr.olemiss.edu/d.xml for$facin doc("http://www.mcsr.olemiss.edu/d.xml")//faculty return$fac/name <faculty> <name>K.Blue</name> <secretary>M.Black</secretary> <ta>Peter</ta> <ta>Bob</ta> <ra>Pam</ra> <ra>DJ</ra> </faculty> 3. List the names of all faculty members (without XML tags) for$facin doc("http://www.mcsr.olemiss.edu/d.xml")//facultyreturndata($fac/name)
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 <faculty> <name>K.Blue</name> <secretary>M.Black</secretary> <ta>Peter</ta> <ta>Bob</ta> <ra>Pam</ra> <ra>DJ</ra> </faculty> <ul> {for$facin doc("http://www.mcsr.olemiss.edu/d.xml")//facultyreturn<li>{data($fac/name)}</li>}</ul>
<ul> {for$facin doc("http://www.mcsr.olemiss.edu/d.xml")//facultyreturn<li>{data($fac/name)}</li>}</ul> 5. List the names of all RAs working for scientists (without XML tags)sorted alphabetically,in an ordered html list. <scientist> <name>L.Young</name> <secretary>P.White</secretary> <ra>Todd</ra> <ra>Ann</ra> <ra>Lisa</ra> </scientist> Who can solve first? <ol> {for$rain doc("http://www.mcsr.olemiss.edu/d.xml")//scientist/raorder bydata ( $ra) return<li>{data($ra) }</li>}</ol>
<ol> {for$rain doc("http://www.mcsr.olemiss.edu/d.xml")//scientist/raorder bydata ( $ra) return<li>{data($ra)}</li>}</ol> <scientist> <name>L.Young</name> <secretary>P.White</secretary> <ra>Todd</ra> <ra>Ann</ra> <ra>Lisa</ra> </scientist> 6. List the secretary names (without XML tags or HTML tags) of all employees,sorted alphabetically Who can solve first? for$secin doc("http://www.mcsr.olemiss.edu/d.xml")//*/secretaryorder bydata( $sec) returndata($sec)
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