Class XPathHelper

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

public final class XPathHelper extends Object
Collection of XPath utility methods.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final ThreadLocal<Boolean>
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Private to avoid instantiation.
  • Method Summary

    Modifier and Type
    Method
    Description
    private static org.htmlunit.xpath.objects.XObject
    evaluateXPath(DomNode contextNode, String str, org.htmlunit.xpath.xml.utils.PrefixResolver prefixResolver)
    Evaluates an XPath expression to an XObject.
    static <T> List<T>
    getByXPath(DomNode node, String xpathExpr, org.htmlunit.xpath.xml.utils.PrefixResolver resolver)
    Evaluates an XPath expression from the specified node, returning the resultant nodes.
    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
  • Field Details

  • Constructor Details

    • XPathHelper

      private XPathHelper()
      Private to avoid instantiation.
  • Method Details

    • getByXPath

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

      private static org.htmlunit.xpath.objects.XObject evaluateXPath(DomNode contextNode, String str, org.htmlunit.xpath.xml.utils.PrefixResolver prefixResolver) throws TransformerException
      Evaluates an XPath expression to an XObject.
      Parameters:
      contextNode - the node to start searching from
      str - a valid XPath string
      prefixResolver - prefix resolver to use for resolving namespace prefixes, or null
      Returns:
      an XObject, which can be used to obtain a string, number, nodelist, etc (should never be null)
      Throws:
      TransformerException - if a syntax or other error occurs