Class XPath

  • public class XPath
    extends Object
    Represent a subset of XPath XML path syntax for use in identifying nodes in parse trees.

    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 = new XPath(parser, pathString);
     return p.evaluate(tree);

    See org.antlr.v4.test.TestXPath for descriptions. In short, this allows operators:

    invert; this must appear directly after root or anywhere operator

    and path elements:

    token name
    any string literal token from the grammar
    rule name
    wildcard matching any node

    Whitespace is not allowed.