Module org.htmlunit

Class XPathHelper

java.lang.Object
org.htmlunit.html.xpath.XPathHelper

public final class XPathHelper extends Object
Collection of XPath utility methods.
Author:
Ahmed Ashour, Chuck Dumont, Ronald Brill
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> List<T>
    getByXPath(DomNode contextNode, String xpathExpr, org.htmlunit.xpath.xml.utils.PrefixResolver prefixResolver)
    Evaluates an XPath expression from the specified node, returning the resultant nodes.
    static <T> List<T>
    getByXPath(Node node, XPathAdapter xpath, org.htmlunit.xpath.xml.utils.PrefixResolver prefixResolver)
    Evaluates the specified XPath expression against the given node and returns the result as a list.
    static boolean
    Returns whether the thread is currently evaluating XPath expression or no.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • getByXPath

      public static <T> List<T> getByXPath(DomNode contextNode, String xpathExpr, org.htmlunit.xpath.xml.utils.PrefixResolver prefixResolver)
      Evaluates an XPath expression from the specified node, returning the resultant nodes.
      Type Parameters:
      T - the type class
      Parameters:
      contextNode - the node to start searching from
      xpathExpr - the XPath expression
      prefixResolver - the prefix resolver to use for resolving namespace prefixes, or null
      Returns:
      the list of objects found
    • getByXPath

      public static <T> List<T> getByXPath(Node node, XPathAdapter xpath, org.htmlunit.xpath.xml.utils.PrefixResolver prefixResolver) throws TransformerException
      Evaluates the specified XPath expression against the given node and returns the result as a list. Depending on the XPath result type, the list contains matching nodes, a single Double, Boolean, or String value.
      Type Parameters:
      T - the type of nodes expected
      Parameters:
      node - the start node
      xpath - the XPathAdapter to search for
      prefixResolver - the PrefixResolver to be used
      Returns:
      a list of nodes matching the given xpath, or a singleton list containing the evaluated number, boolean, or string value
      Throws:
      TransformerException - in case of error
    • isProcessingXPath

      public static boolean isProcessingXPath()
      Returns whether the thread is currently evaluating XPath expression or no.
      Returns:
      whether the thread is currently evaluating XPath expression or no