Presentation is loading. Please wait.

Presentation is loading. Please wait.

Spring 20051 Part III: Introduction to XPath XML Path Language.

Similar presentations

Presentation on theme: "Spring 20051 Part III: Introduction to XPath XML Path Language."— Presentation transcript:

1 Spring Part III: Introduction to XPath XML Path Language

2 2 Example for XPath Queries Addison-Wesley Serge Abiteboul Rick Hull Victor Vianu Foundations of Databases 1995 Freeman Jeffrey D. Ullman Principles of Database and Knowledge Base Systems 1998

3 Spring Data Model for XPath bib book publisherauthor.. Addison-WesleySerge Abiteboul The root The root element Processing instruction Comment price=55

4 Spring XPath: Simple Expressions /bib/book/year Result: /bib/paper/year Result: an empty set of nodes (there were no papers)

5 Spring XPath: Restricted Kleene Closure //author Result: Serge Abiteboul Rick Hull Victor Vianu Jeffrey D. Ullman /bib//first-name Result: Rick A set of 4 nodes

6 Spring XPath: Functions /bib/book/author/text() Result: Serge Abiteboul Victor Vianu Jeffrey D. Ullman Rick Hull doesn’t appear because he has no text node Some functions in XPath: text() = matches text nodes and returns the text value node() = matches any node (regardless of type) name() = returns the name of the current tag

7 Spring XPath: Wildcard //author/* Result: Rick Hull * Matches any element (but not text or attribute)

8 Spring XPath: Attribute Nodes Result: means that price is an Matches any attribute

9 Spring XPath: Qualifiers /bib/book/author[first-name] Result: Rick Hull [first-name] means that author has to have a first-name child element.

10 Spring XPath: More Qualifiers /bib/book/author[first-name][address[zip][city]]/last-name Result: returns all the last names of all authors with a first name and an address which includes city and zip code. […][…] means that author satisfies both qualifiers.

11 Spring XPath: More Qualifiers < 60] /bib/book[author/first-name = “Rick”] /bib/book[author/text()] /bib/book[2] Boolean expressions Existential expression Positional expression

12 Spring XPath: Summary bibmatches a bib element *matches any element /matches the root element /bibmatches a bib element under root bib/papermatches a paper in bib bib//papermatches a paper in bib, at any depth

13 Spring XPath: Summary (cont.) //papermatches a paper at any depth paper|bookmatches a paper or a a price attribute price attribute in book, in bib matches?

14 Spring The Root 1 2 bib is the “document element” The “root” is above bib /bib = returns the document element / = returns the root Why? Because we may have comments before and after … ; they become siblings of bib element. This is advanced xmlogy

15 Spring XPath: More details We can navigate along 13 axes: ancestor ancestor-or-self attribute child descendant descendant-or-self following following-sibling namespace parent preceding preceding-sibling self

16 Spring XPath: More details Examples: child::author/child::last-name = author/last-name child::author/descendant-or-self::node()/child::zip = author//zip child::author/parent::node() = author/.. child::author/attribute::age = What does this mean ? book/publisher/parent::*/author /bib//address[ancestor::book]

17 Spring Shorthand notation Short formLong form ///descendant-or-self::node()/ [number][position() = number]

18 Spring Shorthand notation - Examples Short formLong form /bib/book/child::bib/child::book attribute::price /.//title (equivalent to //title) /self::node()/descendant-or- self::node()/child::title //author/../descendant-or-self::node()/ child::author/parent::node()

19 Spring XPath: Even more details name() = the name of the current node /bib//*[name()=”book”] same as /bib//book What does this mean ? /bib/book/author[.=../following-sibling::*/author and not(.=../preceding-sibling::*/author)] Navigation axis gives us more power !

Download ppt "Spring 20051 Part III: Introduction to XPath XML Path Language."

Similar presentations

Ads by Google