This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full 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.
- Spring '09