PathParsers

public final class PathParsers

functions to find DOM elements in a W3C document. These functions are also useful to experiment and test with how Paths can be used to extract elements (they are used in many of the unit tests of DollarX).

Example use:
Path el = div.before(span);
    String xpath = el.getXPath().get();
    NodeList nodes = findAllByXpath("<div>foo</div><div>boo</div><span></span>", el);
    assertThat(nodes.getLength(), is(2));
    assertThat(nodes.item(0).getTextContent(), equalTo("foo"));

Methods

findAllByPath

public static NodeList findAllByPath(String docString, Path path)

find all the nodes that match a path in a W3C document

Parameters:
  • docString – a W3C document
  • path – the path to find.
Returns:

a node list with the details of all the elements that match the given path

findAllByPath

public static NodeList findAllByPath(Document doc, Path path)

find all the nodes that match a path in a W3C document

Parameters:
  • doc – a W3C document
  • path – the path to find
Returns:

a node list with the details of all the elements that match the given path

findAllByXPath

public static NodeList findAllByXPath(Document doc, String extractedXpath)

internal implementation

Parameters:
  • doc – a W3C document
  • extractedXpath – an xpath
Returns:

a node list with the details of all the elements that match the given xpath

getDocumentFromString

public static Document getDocumentFromString(String document)

Convert a string to a Document, Assuming utf-8 encoding.

Parameters:
  • document – the document as a string
Returns:

the document as a @link Document}