public class XPath
extends java.lang.Object
Split path into words and separators /
and //
via ANTLR
itself then walk path elements from left to right. At each separator-word
pair, find set of nodes. Next stage uses those as work list.
The basic interface is
ParseTree.findAll
(tree, pathString, parser)
.
But that is just shorthand for:
XPath
p = newXPath
(parser, pathString); return p.evaluate
(tree);
See org.antlr.v4.test.TestXPath
for descriptions. In short, this
allows operators:
and path elements:
Whitespace is not allowed.
Modifier and Type | Field and Description |
---|---|
protected XPathElement[] |
elements |
static java.lang.String |
NOT |
protected Parser |
parser |
protected java.lang.String |
path |
static java.lang.String |
WILDCARD |
Constructor and Description |
---|
XPath(Parser parser,
java.lang.String path) |
Modifier and Type | Method and Description |
---|---|
java.util.Collection<ParseTree> |
evaluate(ParseTree t)
Return a list of all nodes starting at
t as root that satisfy the
path. |
static java.util.Collection<ParseTree> |
findAll(ParseTree tree,
java.lang.String xpath,
Parser parser) |
protected XPathElement |
getXPathElement(Token wordToken,
boolean anywhere)
Convert word like
* or ID or expr to a path
element. |
XPathElement[] |
split(java.lang.String path) |
public static final java.lang.String WILDCARD
public static final java.lang.String NOT
protected java.lang.String path
protected XPathElement[] elements
protected Parser parser
public XPath(Parser parser, java.lang.String path)
public XPathElement[] split(java.lang.String path)
protected XPathElement getXPathElement(Token wordToken, boolean anywhere)
*
or ID
or expr
to a path
element. anywhere
is true
if //
precedes the
word.public static java.util.Collection<ParseTree> findAll(ParseTree tree, java.lang.String xpath, Parser parser)
public java.util.Collection<ParseTree> evaluate(ParseTree t)
t
as root that satisfy the
path. The root /
is relative to the node passed to
evaluate(org.antlr.v4.runtime.tree.ParseTree)
.