{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

12-xml - Announcements(Thu Oct 20 XPath and XQuery CPS 116...

Info icon This preview shows pages 1–3. 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 (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
Image of page 1

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

View Full Document Right Arrow Icon
2 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<[email protected] and @price<=50] Books authored by “Abiteboul” or those with price lower than $50 /bibliography/book[author=“Abiteboul” or @price<50] 10 Predicates involving node-sets /bibliography/book[author=‘Abiteboul’] There may be multiple authors, so author in
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern