Class XPathHelper


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

      Fields 
      Modifier and Type Field Description
      private static java.lang.ThreadLocal<java.lang.Boolean> PROCESS_XPATH_  
    • Constructor Summary

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

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      private static org.htmlunit.xpath.objects.XObject evaluateXPath​(DomNode contextNode, java.lang.String str, org.htmlunit.xpath.xml.utils.PrefixResolver prefixResolver)
      Evaluates an XPath expression to an XObject.
      static <T> java.util.List<T> getByXPath​(DomNode node, java.lang.String xpathExpr, org.htmlunit.xpath.xml.utils.PrefixResolver resolver)
      Evaluates an XPath expression from the specified node, returning the resultant nodes.
      static boolean isProcessingXPath()
      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 Detail

      • PROCESS_XPATH_

        private static final java.lang.ThreadLocal<java.lang.Boolean> PROCESS_XPATH_
    • Constructor Detail

      • XPathHelper

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

      • getByXPath

        public static <T> java.util.List<T> getByXPath​(DomNode node,
                                                       java.lang.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,
                                                                        java.lang.String str,
                                                                        org.htmlunit.xpath.xml.utils.PrefixResolver prefixResolver)
                                                                 throws javax.xml.transform.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:
        javax.xml.transform.TransformerException - if a syntax or other error occurs