1
XPath
- Asst. Prof. Dr. Kanda Runapongsa Saikaew
(krunapon@kku.ac.th)
- Dept. of Computer Engineering
XPath Asst. Prof. Dr. Kanda Runapongsa Saikaew (krunapon@kku.ac.th) - - PowerPoint PPT Presentation
XPath Asst. Prof. Dr. Kanda Runapongsa Saikaew (krunapon@kku.ac.th) Dept. of Computer Engineering Khon Kaen University 1 Overview What is XPath? Queries The XPath Data Model Location Paths Expressions XPath Engines 2
1
2
What is XPath? Queries The XPath Data Model Location Paths Expressions XPath Engines
3
4
XPath is a declarative language for
An XPath location path says which
XPath can be thought of a query
However, rather than extracting
5
6
root node element node attribute node text node comment node processing instruction node namespace node
7
The XPath data model is similar to,
The most important differences relate
In XPath, only attributes, elements,
In XPath, the value of an element node
8
For example, the XPath value of
XPath does not have separate nodes
9
XPath does not include any
All entity references must be resolved
Once entity references are resolved,
10
11
12
Although there are many different
13
Each location step has an axis, a
Each location step is evaluated with
A double colon (::) separates the axis
Syntax for a location path
14
15
Let‟s pick the root methodCal
Then child::
That is, it selects all the children of the
child::pa
16
17
child: All child nodes of the context
descendant: All nodes completely
18
descendant-or-self: All descendants
parent: The node which most
ancestor: The root node and all
19
20
21
following-sibling All non-attribute, non-namespace
attribute Attributes of the context node. This
namespace Namespaces in scope of the
22
They do not
They together
self ancestor preceding following descendant
23
The axis chooses the direction to
The node test determines what kinds
Example: child::params child is an axis name params is a note test
24
name Match any element or attribute with
* Along the attribute axis the asterisk
Along the namespace axis the asterisk
Along all other axes, this matches all
25
26
27
Each location step can have zero or
A predicate is an XPath expression in
If the predicate is true, then the node
28
The forward slash (/) combines
The node-set selected by the first
The node-set identified by the second
29
Unabbreviated Path Expression Examples (1/2)
child::p
child::*
child::tex
child::n
30
Unabbreviated Path Expression Examples (2/2)
attrib
parent::n
If the context node is an attribute node, this
expression returns the element node to which the attribute node is attached
descend
31
In particular, a location path that
/ selects the root node of the
32
33
Abbrevia reviation
Expanded anded from Name child::Name @Name attribute::Name // /descendant-or-self::node()/ . self::node() .. parent::node()
34
35
//stk:Price | //stk:Quote
36
37
38
XPath string literals are enclosed in
For example, “red” and „red‟ are
There are no boolean or node-set
However, the true() and false()
39
XPath provides the following
+ addition - subtraction * multiplication div division mod taking the remainder
40
< less than > greater than <= less than or equal to >= greater than or equal to = boolean equals (not an assignment
!= not equal to or Boolean or and Boolean and
41
42
number last() Returns the number of nodes in the
number position() Returns the position of the context
number count(node-set) Returns the number of nodes in the
43
boolean boolean(object) Converts the argument to a
NaN and 0 are false. All other
Empty strings are false. All other
Empty node-sets are false. All other
44
45
string string(object?) This function returns the string-
string concat(string, string, string …) This function returns a string
46
47
string substring(string, number,
This returns the substring of the
Beginning at the second argument Continuing for the number of
Or until the end of the string if the
48
49
50
51
Path Expressions with Functions/Predicates (1/2)
child::para[
child::para[
child::chap
52
Path Expressions with Functions/Predicates (2/2)
para[1] selects the first para child of
para[@type=“warning”][5] selects the
para[5][@type=“warning”] selects the
53
Comments may be used to provide
Comments are lexical constructs only,
Comments are strings, delimited by
An example of a comment
54
XPath Explorer (XPE) is a GUI application
Given an XPath expression and URL (to an
This makes it easy to play with and debug
For more Info http://sourceforge.net/projects/xpe
55
XPath is a straightforward declarative
XPath location paths are composed
Each location step has an axis and a
56
Each location step is evaluated with
The axis determines in which
The node test determines which
The predicate decides which of the
57
XML Path Language (XPath
W3Schools XPath Tutorial
Zvon XPath Tutorial