1 / 32

XQuery 1.0: An XQL Query Language

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 . ...

onawa
Télécharger la présentation

XQuery 1.0: An XQL Query Language

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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, A Relational Schema

  6. The personnel of a department can be faculty, lecturers, A Relational Schema

  7. The personnel of a department can be faculty, lecturers, or scientists. A Relational Schema

  8. They may or may not have a secretary. A Relational Schema

  9. A lecturer can have TAs, no RAs.

  10. A scientist can have RAs, but no TAs.

  11. Each faculty may have both TAs and RAs.

  12. 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.

  13. XML <department> <staff> ….. </staff> <faculty> ….</faculty> <lecturer> ….</lecturer> <scientist> ….</scientist></department> The personnel of a department can be staff, faculty, lecturers, or scientists.

  14. 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.

  15. 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.

  16. 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.

  17. 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.

  18. 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.

  19. 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..

  20. 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.

  21. 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

  22. 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 ]

  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, staffwhere faculty.id = staff.id Enter the query in the text box of the web pageand 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. <faculty> <name>K.Blue</name> <secretary>M.Black</secretary></faculty> for$facin doc("http://www.mcsr.olemiss.edu/d.xml")//faculty return$fac/name

  26. 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

  27. 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

  28. 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)

  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 <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>

  30. <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>

  31. <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)

  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

More Related