12-xml-notes

12-xml-notes - XPath and XQuery CPS 116 Introduction to...

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

View Full Document Right Arrow Icon
1 XPath and XQuery CPS 116 Introduction to Database Systems 2 Announcements (Tue. Oct. 18) ± 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
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 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
Background image of page 2
3 7 Simple XPath examples ± All book titles /bibliography/book/title ± All book ISBN numbers /bibliography/book/@ISBN ± 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’]/@price 9 More complex predicates Predicates can have and ’s and or ’s ± Books with price between $40 and $50 /bibliography/book[40<=@price and @price<=50]
Background image of page 3

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

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

This document was uploaded on 01/17/2012.

Page1 / 12

12-xml-notes - XPath and XQuery CPS 116 Introduction to...

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

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