Package org.htmlcleaner
Class XPather
- java.lang.Object
-
- org.htmlcleaner.XPather
-
public class XPather extends java.lang.ObjectUtility for searching cleaned document tree with XPath expressions.
Examples of supported axes:- //div//a
- //div//a[@id][@class]
- /body/*[1]/@type
- //div[3]//a[@id][@href='r/n4']
- //div[last() >= 4]//./div[position() = last()])[position() > 22]//li[2]//a
- //div[2]/@*[2]
- data(//div//a[@id][@class])
- //p/last()
- //body//div[3][@class]//span[12.2
- data(//a['v' < @id])
-
-
Constructor Summary
Constructors Constructor Description XPather(java.lang.String expression)Constructor - creates XPather instance with specified XPath expression.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.util.CollectionevaluateAgainst(java.util.Collection object, int from, int to, boolean isRecursive, int position, int last, boolean isFilterContext, java.util.Collection filterSource)java.lang.Object[]evaluateAgainstNode(TagNode node)Main public method for this class - a way to execute XPath expression against specified TagNode instance.protected java.util.CollectionevaluateFunction(java.util.Collection source, int from, int to, int position, int last, boolean isFilterContext)Evaluates specified function.protected booleanevaluateLogic(java.util.Collection first, java.util.Collection second, java.lang.String logicOperator)Evaluates logic operation on two collections.protected java.util.CollectionfilterByCondition(java.util.Collection source, int from, int to)Filter nodes satisfying the condition
-
-
-
Method Detail
-
evaluateAgainstNode
public java.lang.Object[] evaluateAgainstNode(TagNode node) throws XPatherException
Main public method for this class - a way to execute XPath expression against specified TagNode instance.- Parameters:
node-- Throws:
XPatherException
-
evaluateAgainst
protected java.util.Collection evaluateAgainst(java.util.Collection object, int from, int to, boolean isRecursive, int position, int last, boolean isFilterContext, java.util.Collection filterSource) throws XPatherException- Throws:
XPatherException
-
evaluateFunction
protected java.util.Collection evaluateFunction(java.util.Collection source, int from, int to, int position, int last, boolean isFilterContext) throws XPatherExceptionEvaluates specified function. Currently, following XPath functions are supported: last, position, text, count, data- Parameters:
source-from-to-position-last-- Returns:
- Collection as the result of evaluation.
- Throws:
XPatherException
-
filterByCondition
protected java.util.Collection filterByCondition(java.util.Collection source, int from, int to) throws XPatherExceptionFilter nodes satisfying the condition- Parameters:
source-from-to-- Throws:
XPatherException
-
evaluateLogic
protected boolean evaluateLogic(java.util.Collection first, java.util.Collection second, java.lang.String logicOperator)Evaluates logic operation on two collections.- Parameters:
first-second-logicOperator-- Returns:
- Result of logic operation
-
-