Package com.github.loyada.jdollarx
Class PathParsers
- java.lang.Object
-
- com.github.loyada.jdollarx.PathParsers
-
public final class PathParsers extends Object
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"));
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static NodeListfindAllByPath(String docString, Path path)find all the nodes that match a path in a W3C documentstatic NodeListfindAllByPath(Document doc, Path path)find all the nodes that match a path in a W3C documentstatic NodeListfindAllByXPath(Document doc, String extractedXpath)internal implementationstatic DocumentgetDocumentFromString(String document)Convert a string to aDocument, Assuming utf-8 encoding.
-
-
-
Method Detail
-
getDocumentFromString
public static Document getDocumentFromString(String document) throws ParserConfigurationException, IOException, SAXException
Convert a string to aDocument, Assuming utf-8 encoding.- Parameters:
document- the document as a string- Returns:
- the document as a @link Document}
- Throws:
ParserConfigurationExceptionIOExceptionSAXException
-
findAllByPath
public static NodeList findAllByPath(String docString, Path path) throws XPathExpressionException, IOException, SAXException, ParserConfigurationException
find all the nodes that match a path in a W3C document- Parameters:
docString- a W3C documentpath- the path to find.- Returns:
- a node list with the details of all the elements that match the given path
- Throws:
XPathExpressionExceptionIOExceptionSAXExceptionParserConfigurationException
-
findAllByPath
public static NodeList findAllByPath(Document doc, Path path) throws XPathExpressionException
find all the nodes that match a path in a W3C document- Parameters:
doc- a W3C documentpath- the path to find- Returns:
- a node list with the details of all the elements that match the given path
- Throws:
XPathExpressionException
-
findAllByXPath
public static NodeList findAllByXPath(Document doc, String extractedXpath) throws XPathExpressionException
internal implementation- Parameters:
doc- a W3C documentextractedXpath- an xpath- Returns:
- a node list with the details of all the elements that match the given xpath
- Throws:
XPathExpressionException
-
-