12-xml

12-xml - 1 XPath and XQuery CPS 116 Introduction to Database Systems 2 Announcements(Thu Oct 20 Project milestone#1 feedback available by this

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1 XPath and XQuery CPS 116 Introduction to Database Systems 2 Announcements (Thu. Oct. 20) ¡ Project milestone #1 feedback available by this weekend via email ¡ Homework #3 out ¢ Due Nov. 3 (two weeks from now) ¡ Homework #2 graded ¢ Please check Blackboard for mistakes or omissions! ) Old handouts and graded assignments/exams in the handout box outside my office 3 Query languages for XML ¡ XPath ¢ Path expressions with conditions ) Building block of other standards (XQuery, XSLT, XLink, XPointer, etc.) ¡ XQuery ¢ XPath + full-fledged SQL-like query language ¡ XSLT ¢ XPath + transformation templates 4 Example DTD and XML <?xml version=“1.0”?> <!DOCTYPE bibliography [ <!ELEMENT bibliography (book+)> <!ELEMENT book (title, author*, publisher?, year?, section*)> <!ATTLIST book ISBN CDATA #REQUIRED> <!ATTLIST book price CDATA #IMPLIED> <!ELEMENT title (#PCDATA)> <!ELEMENT author (#PCDATA)> <!ELEMENT publisher (#PCDATA)> <!ELEMENT year (#PCDATA)> <!ELEMENT i (#PCDATA)> <!ELEMENT content (#PCDATA|i)*> <!ELEMENT section (title, content?, section*)> ]> <bibliography> <book ISBN=”ISBN-10” price=”80.00”> <title>Foundations of Databases</title> <author>Abiteboul</author> <author>Hull</author> <author>Vianu</author> <publisher>Addison Wesley</publisher> <year>1995</year> <section>…</section>… </book> … </bibliography> 5 XPath ¡ XPath specifies path expressions that match XML data by navigating down (and occasionally up and across) the tree ¡ Example ¢ Query: /bibliography/book/author • Like a UNIX path ¢ Result: all author elements reachable from root via the path /bibliography/book/author 6 Basic XPath constructs / separator between steps in a path name matches any child element with this tag name * matches any child element @ name matches the attribute with this name @* matches any attribute // matches any descendent element or the current element itself . matches the current element .. matches the parent element 2 7 Simple XPath examples ¡ All book titles /bibliography/book/title ¡ All book ISBN numbers [email protected] ¡ All title elements, anywhere in the document //title ¡ All section titles, anywhere in the document //section/title ¡ Authors of bibliographical entries (suppose there are articles, reports, etc. in addition to books) /bibliography/*/author 8 Predicates in path expressions [ condition ] matches the “current” element if condition evaluates to true on the current element ¡ Books with price lower than $50 /bibliography/book[@price<50] ¢ XPath will automatically convert the price string to a numeric value for comparison ¡ Books with author “Abiteboul” /bibliography/book[author=‘Abiteboul’] ¡ Books with a publisher child element /bibliography/book[publisher] ¡ Prices of books authored by “Abiteboul” /bibliography/book[author=‘Abiteboul’][email protected] 9 More complex predicates Predicates can have and ’s and or ’s ¡ Books with price between $40 and $50 /bibliography/book[40<[email protected] and @price<=50]...
View Full Document

This document was uploaded on 01/17/2012.

Page1 / 6

12-xml - 1 XPath and XQuery CPS 116 Introduction to Database Systems 2 Announcements(Thu Oct 20 Project milestone#1 feedback available by this

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online