Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 XPath Path Expressions Conditions. 2 Paths in XML Documents uXPath is a language for describing paths in XML documents. uReally think of the semistructured.

Similar presentations


Presentation on theme: "1 XPath Path Expressions Conditions. 2 Paths in XML Documents uXPath is a language for describing paths in XML documents. uReally think of the semistructured."— Presentation transcript:

1 1 XPath Path Expressions Conditions

2 2 Paths in XML Documents uXPath is a language for describing paths in XML documents. uReally think of the semistructured data graph and its paths.

3 3 Example DTD <!DOCTYPE BARS [ ]>

4 4 Example Document 2.50 3.00 … <BEER name = “Bud” soldBy = “JoesBar SuesBar … ”/> …

5 5 Path Descriptors uSimple path descriptors are sequences of tags separated by slashes (/). uIf the descriptor begins with /, then the path starts at the root and has those tags, in order. uIf the descriptor begins with //, then the path can start anywhere.

6 6 Value of a Path Descriptor uEach path descriptor, applied to a document, has a value that is a sequence of elements. uAn element is an atomic value or a node. uA node is matching tags and everything in between. wI.e., a node of the semistructured graph.

7 7 Example: /BARS/BAR/PRICE 2.50 3.00 … <BEER name = “Bud” soldBy = “JoesBar SuesBar …”/> … /BARS/BAR/PRICE describes the set with these two PRICE elements as well as the PRICE elements for any other bars.

8 8 Example: //PRICE 2.50 3.00 … <BEER name = “Bud” soldBy = “JoesBar SuesBar …”/>… //PRICE describes the same PRICE elements, but only because the DTD forces every PRICE to appear within a BARS and a BAR.

9 9 Wild-Card * uA star (*) in place of a tag represents any one tag. uExample: /*/*/PRICE represents all price objects at the third level of nesting.

10 10 Example: /BARS/* 2.50 3.00 … <BEER name = “Bud” soldBy = “JoesBar SuesBar …”/> … /BARS/* captures all BAR and BEER elements, such as these.

11 11 Attributes uIn XPath, we refer to attributes by prepending @ to their name. uAttributes of a tag may appear in paths as if they were nested within that tag.

12 12 Example: /BARS/*/@name 2.50 3.00 … <BEER name = “Bud” soldBy = “JoesBar SuesBar …”/> … /BARS/*/@name selects all name attributes of immediate subelements of the BARS element.

13 13 Selection Conditions uA condition inside […] may follow a tag. uIf so, then only paths that have that tag and also satisfy the condition are included in the result of a path expression.

14 14 Example: Selection Condition u/BARS/BAR[PRICE < 2.75]/PRICE 2.50 3.00 … The condition that the PRICE be < $2.75 makes this price but not the Miller price satisfy the path descriptor.

15 15 Example: Attribute in Selection u/BARS/BAR/PRICE[@theBeer = “Miller”] 2.50 3.00 … Now, this PRICE element is selected, along with any other prices for Miller.

16 16 Axes uIn general, path expressions allow us to start at the root and execute steps to find a sequence of nodes at each step. uAt each step, we may follow any one of several axes. uThe default axis is child:: --- go to all the children of the current set of nodes.

17 17 Example: Axes u/BARS/BEER is really shorthand for /BARS/child::BEER. u@ is really shorthand for the attribute:: axis. wThus, /BARS/BEER[@name = “Bud” ] is shorthand for /BARS/BEER[attribute::name = “Bud”]

18 18 More Axes uSome other useful axes are: 1.parent:: = parent(s) of the current node(s). 2.descendant-or-self:: = the current node(s) and all descendants. wNote: // is really shorthand for this axis. 3.ancestor::, ancestor-or-self, etc.


Download ppt "1 XPath Path Expressions Conditions. 2 Paths in XML Documents uXPath is a language for describing paths in XML documents. uReally think of the semistructured."

Similar presentations


Ads by Google