Presentation is loading. Please wait.

Presentation is loading. Please wait.

XML path expressions CSE 350 Fall 2003.

Similar presentations


Presentation on theme: "XML path expressions CSE 350 Fall 2003."— Presentation transcript:

1 XML path expressions CSE 350 Fall 2003

2 Xpath: XML Path language
(11/99) Building block for other W3C standards: XSL Transformations (XSLT) XML Link (XLink) XML Pointer (XPointer) XML Query Input and output are XML

3 Example for XPath Queries
<bib> <book> <publisher> Addison-Wesley </publisher> <author> Serge Abiteboul </author> <author> <first-name> Rick </first-name> <last-name> Hull </last-name> </author> <author> Victor Vianu </author> <title> Foundations of Databases </title> <year> 1995 </year> </book> <book price=“55”> <publisher> Freeman </publisher> <author> Jeffrey D. Ullman </author> <title> Principles of Database and Knowledge Base Systems </title> <year> 1998 </year> </book> </bib>

4 XPath: Simple Expressions
Example 1: /bib/book/year Result: <year> 1995 </year> <year> 1998 </year> Example 2: /bib/paper/year Result: empty (there were no papers) Given an OEM instance, the value of a path expression p is a set of objects

5 XPath: Restricted Kleene Closure
Example 3: //author Result:<author> Serge Abiteboul </author> <author> <first-name> Rick </first-name> <last-name> Hull </last-name> </author> <author> Victor Vianu </author> <author> Jeffrey D. Ullman </author> Example 4: /bib//first-name Result: <first-name> Rick </first-name>

6 Xpath Functions Functions in XPath: Example 5: /bib/book/author/text()
text() = matches the text value node() = matches any node (= * or text()) name() = returns the name of the current tag Example 5: /bib/book/author/text() Result: Serge Abiteboul Jeffrey D. Ullman (Rick Hull doesn’t appear because he has firstname, lastname)

7 More Xpath syntax Wildcard: Attribute:
* Matches any element Example 6: //author/* Result: <first-name> Rick </first-name> <last-name> Hull </last-name> Attribute: @price means that price is has to be an attribute Example 7: Result: “55”

8 Xpath: Qualifiers More examples (9,10,11): /bib/book[@price < “60”]
Example 8: /bib/book/author[firstname] Result: <author> <first-name> Rick </first-name> <last-name> Hull </last-name> </author> More examples (9,10,11): < “60”] < “25”] /bib/book[author/text()]

9 Path Expressions Example
&96 &243 &206 &25 “Serge” “Abiteboul” 1997 “Victor” “Vianu” 122 133 paper book references author title year http publisher page firstname lastname first last Bib &o44 &o45 &o46 &o47 &o48 &o49 &o50 &o51 &o52 Example: DB = Bib.paper={&o12,&o29} Bib.book.publisher= ? Bib.paper.author.lastname= ?

10 Regular Path Expressions
R ::= label | _ | R.R | (R|R) | R* | R+ | R? Examples: Bib.(paper|book).author Bib.book.author.lastname? Bib.book.(references)*.author Bib.(_)*.zip Answer is: U{eval(root(DB), P) | P  lang(R)} where lang(R) = the set of strings generated by R

11 Xpath: Summary bib matches a bib element * matches any element
/ matches the root element /bib matches a bib element under root bib/paper matches a paper in bib bib//paper matches a paper in bib, at any depth //paper matches a paper at any depth paper|book matches a paper or a book @price matches a price attribute matches price attribute in book, in bib matches…

12 Definition Intuition:
find all objects x in DB s.t. the path from DB root to object x matches the path expression P Path expression P over DB evaluates to eval(root(DB), P) eval(x,e) = {x} eval(x,L.P) = U {eval(y,P) | (x, L, y) edges(DB)}

13 Applications of Path Expressions
Navigating uncertain structure: Bib.book.author.lastname? Syntactic substitute for inheritance: Bib.(paper|book).author Bib.publication.author better, but we don’t have inheritance Computing transitive closure: Bib.(_)*.zip all accessible zipcodes Bib.book.(references)*.author all authors accessible via book references


Download ppt "XML path expressions CSE 350 Fall 2003."

Similar presentations


Ads by Google