• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.gitignoreH A D15-May-2020306

.travis.ymlH A D15-May-2020151

LICENSEH A D15-May-20201,022

README.mdH A D15-May-20205.1 KiB

build.goH A D15-May-202013.8 KiB

doc_test.goH A D15-May-2020715

func.goH A D15-May-202012.3 KiB

func_go110.goH A D15-May-2020105

func_pre_go110.goH A D15-May-2020293

operator.goH A D15-May-20206 KiB

parse.goH A D15-May-202025.4 KiB

query.goH A D15-May-202018.3 KiB

xpath.goH A D15-May-20204 KiB

xpath_test.goH A D15-May-202022.2 KiB

README.md

1XPath
2====
3[![GoDoc](https://godoc.org/github.com/antchfx/xpath?status.svg)](https://godoc.org/github.com/antchfx/xpath)
4[![Coverage Status](https://coveralls.io/repos/github/antchfx/xpath/badge.svg?branch=master)](https://coveralls.io/github/antchfx/xpath?branch=master)
5[![Build Status](https://travis-ci.org/antchfx/xpath.svg?branch=master)](https://travis-ci.org/antchfx/xpath)
6[![Go Report Card](https://goreportcard.com/badge/github.com/antchfx/xpath)](https://goreportcard.com/report/github.com/antchfx/xpath)
7
8XPath is Go package provides selecting nodes from XML, HTML or other documents using XPath expression.
9
10Implementation
11===
12
13- [htmlquery](https://github.com/antchfx/htmlquery) - an XPath query package for HTML document
14
15- [xmlquery](https://github.com/antchfx/xmlquery) - an XPath query package for XML document.
16
17- [jsonquery](https://github.com/antchfx/jsonquery) - an XPath query package for JSON document
18
19Supported Features
20===
21
22#### The basic XPath patterns.
23
24> The basic XPath patterns cover 90% of the cases that most stylesheets will need.
25
26- `node` : Selects all child elements with nodeName of node.
27
28- `*` : Selects all child elements.
29
30- `@attr` : Selects the attribute attr.
31
32- `@*` : Selects all attributes.
33
34- `node()` : Matches an org.w3c.dom.Node.
35
36- `text()` : Matches a org.w3c.dom.Text node.
37
38- `comment()` : Matches a comment.
39
40- `.` : Selects the current node.
41
42- `..` : Selects the parent of current node.
43
44- `/` : Selects the document node.
45
46- `a[expr]` : Select only those nodes matching a which also satisfy the expression expr.
47
48- `a[n]` : Selects the nth matching node matching a When a filter's expression is a number, XPath selects based on position.
49
50- `a/b` : For each node matching a, add the nodes matching b to the result.
51
52- `a//b` : For each node matching a, add the descendant nodes matching b to the result.
53
54- `//b` : Returns elements in the entire document matching b.
55
56- `a|b` : All nodes matching a or b, union operation(not boolean or).
57
58- `(a, b, c)` : Evaluates each of its operands and concatenates the resulting sequences, in order, into a single result sequence
59
60
61#### Node Axes
62
63- `child::*` : The child axis selects children of the current node.
64
65- `descendant::*` : The descendant axis selects descendants of the current node. It is equivalent to '//'.
66
67- `descendant-or-self::*` : Selects descendants including the current node.
68
69- `attribute::*` : Selects attributes of the current element. It is equivalent to @*
70
71- `following-sibling::*` : Selects nodes after the current node.
72
73- `preceding-sibling::*` : Selects nodes before the current node.
74
75- `following::*` : Selects the first matching node following in document order, excluding descendants.
76
77- `preceding::*` : Selects the first matching node preceding in document order, excluding ancestors.
78
79- `parent::*` : Selects the parent if it matches. The '..' pattern from the core is equivalent to 'parent::node()'.
80
81- `ancestor::*` : Selects matching ancestors.
82
83- `ancestor-or-self::*` : Selects ancestors including the current node.
84
85- `self::*` : Selects the current node. '.' is equivalent to 'self::node()'.
86
87#### Expressions
88
89 The gxpath supported three types: number, boolean, string.
90
91- `path` : Selects nodes based on the path.
92
93- `a = b` : Standard comparisons.
94
95    * a = b	    True if a equals b.
96    * a != b	True if a is not equal to b.
97    * a < b	    True if a is less than b.
98    * a <= b	True if a is less than or equal to b.
99    * a > b	    True if a is greater than b.
100    * a >= b	True if a is greater than or equal to b.
101
102- `a + b` : Arithmetic expressions.
103
104    * `- a`	Unary minus
105    * a + b	Add
106    * a - b	Substract
107    * a * b	Multiply
108    * a div b	Divide
109    * a mod b	Floating point mod, like Java.
110
111- `a or b` : Boolean `or` operation.
112
113- `a and b` : Boolean `and` operation.
114
115- `(expr)` : Parenthesized expressions.
116
117- `fun(arg1, ..., argn)` : Function calls:
118
119| Function | Supported |
120| --- | --- |
121`boolean()`| ✓ |
122`ceiling()`| ✓ |
123`choose()`| ✗ |
124`concat()`| ✓ |
125`contains()`| ✓ |
126`count()`| ✓ |
127`current()`| ✗ |
128`document()`| ✗ |
129`element-available()`| ✗ |
130`ends-with()`| ✓ |
131`false()`| ✓ |
132`floor()`| ✓ |
133`format-number()`| ✗ |
134`function-available()`| ✗ |
135`generate-id()`| ✗ |
136`id()`| ✗ |
137`key()`| ✗ |
138`lang()`| ✗ |
139`last()`| ✓ |
140`local-name()`| ✓ |
141`name()`| ✓ |
142`namespace-uri()`| ✓ |
143`normalize-space()`| ✓ |
144`not()`| ✓ |
145`number()`| ✓ |
146`position()`| ✓ |
147`replace()`| ✓ |
148`reverse()`| ✓ |
149`round()`| ✓ |
150`starts-with()`| ✓ |
151`string()`| ✓ |
152`string-length()`| ✓ |
153`substring()`| ✓ |
154`substring-after()`| ✓ |
155`substring-before()`| ✓ |
156`sum()`| ✓ |
157`system-property()`| ✗ |
158`translate()`| ✓ |
159`true()`| ✓ |
160`unparsed-entity-url()` | ✗ |
161
162Changelogs
163===
164
1652019-03-19
166- optimize XPath `|` operation performance. [#33](https://github.com/antchfx/xpath/issues/33). Tips: suggest split into multiple subquery if you have a lot of `|` operations.
167
1682019-01-29
169-  improvement `normalize-space` function. [#32](https://github.com/antchfx/xpath/issues/32)
170
1712018-12-07
172-  supports XPath 2.0 Sequence expressions. [#30](https://github.com/antchfx/xpath/pull/30) by [@minherz](https://github.com/minherz).