Package org.htmlunit.xpath
Class XPath
- java.lang.Object
-
- org.htmlunit.xpath.XPath
-
public class XPath extends java.lang.ObjectThe XPath class wraps an expression object and provides general services for execution of that expression.
-
-
Field Summary
Fields Modifier and Type Field Description private FunctionTablem_funcTableThe function table for xpath build-in functionsprivate Expressionm_mainExpThe top of the expression tree.static intMATCHRepresents a match type expression.static doubleMATCH_SCORE_NODETESTThe match score if the pattern consists of just a NodeTest.static doubleMATCH_SCORE_NONEThe match score if no match is made.static doubleMATCH_SCORE_NSWILDThe match score if the pattern pattern has the form NCName:*.static doubleMATCH_SCORE_OTHERThe match score if the pattern consists of something other than just a NodeTest or just a qname.static doubleMATCH_SCORE_QNAMEThe match score if the pattern has the form of a QName optionally preceded by an @ character.static intSELECTRepresents a select type expression.
-
Constructor Summary
Constructors Constructor Description XPath(java.lang.String exprString, PrefixResolver prefixResolver, int type)Construct an XPath object.XPath(java.lang.String exprString, PrefixResolver prefixResolver, int type, javax.xml.transform.ErrorListener errorListener)Construct an XPath object.XPath(java.lang.String exprString, PrefixResolver prefixResolver, int type, javax.xml.transform.ErrorListener errorListener, FunctionTable aTable)Construct an XPath object.XPath(Expression expr)Construct an XPath object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcallVisitors(XPathVisitor visitor)This will traverse the heararchy, calling the visitor for each member.voiderror(XPathContext xctxt, java.lang.String msg, java.lang.Object[] args)Tell the user of an error, and probably throw an exception.XObjectexecute(XPathContext xctxt, int contextNode, PrefixResolver namespaceContext)Given an expression and a context, evaluate the XPath and return the result.XObjectexecute(XPathContext xctxt, org.w3c.dom.Node contextNode, PrefixResolver namespaceContext)Given an expression and a context, evaluate the XPath and return the result.javax.xml.transform.SourceLocatorgetLocator()Get the SourceLocator on the expression object.private voidinitFunctionTable()initial the function table
-
-
-
Field Detail
-
m_mainExp
private final Expression m_mainExp
The top of the expression tree.
-
m_funcTable
private transient FunctionTable m_funcTable
The function table for xpath build-in functions
-
SELECT
public static final int SELECT
Represents a select type expression.- See Also:
- Constant Field Values
-
MATCH
public static final int MATCH
Represents a match type expression.- See Also:
- Constant Field Values
-
MATCH_SCORE_NONE
public static final double MATCH_SCORE_NONE
The match score if no match is made.- See Also:
- Constant Field Values
-
MATCH_SCORE_QNAME
public static final double MATCH_SCORE_QNAME
The match score if the pattern has the form of a QName optionally preceded by an @ character.- See Also:
- Constant Field Values
-
MATCH_SCORE_NSWILD
public static final double MATCH_SCORE_NSWILD
The match score if the pattern pattern has the form NCName:*.- See Also:
- Constant Field Values
-
MATCH_SCORE_NODETEST
public static final double MATCH_SCORE_NODETEST
The match score if the pattern consists of just a NodeTest.- See Also:
- Constant Field Values
-
MATCH_SCORE_OTHER
public static final double MATCH_SCORE_OTHER
The match score if the pattern consists of something other than just a NodeTest or just a qname.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
XPath
public XPath(java.lang.String exprString, PrefixResolver prefixResolver, int type, javax.xml.transform.ErrorListener errorListener) throws javax.xml.transform.TransformerExceptionConstruct an XPath object.(Needs review -sc) This method initializes an XPathParser/ Compiler and compiles the expression.
- Parameters:
exprString- The XPath expression.prefixResolver- A prefix resolver to use to resolve prefixes to namespace URIs.type- one ofSELECTorMATCH.errorListener- The error listener, or null if default should be used.- Throws:
javax.xml.transform.TransformerException- if syntax or other error.
-
XPath
public XPath(java.lang.String exprString, PrefixResolver prefixResolver, int type, javax.xml.transform.ErrorListener errorListener, FunctionTable aTable) throws javax.xml.transform.TransformerExceptionConstruct an XPath object.(Needs review -sc) This method initializes an XPathParser/ Compiler and compiles the expression.
- Parameters:
exprString- The XPath expression.prefixResolver- A prefix resolver to use to resolve prefixes to namespace URIs.type- one ofSELECTorMATCH.errorListener- The error listener, or null if default should be used.aTable- the function table to be used- Throws:
javax.xml.transform.TransformerException- if syntax or other error.
-
XPath
public XPath(java.lang.String exprString, PrefixResolver prefixResolver, int type) throws javax.xml.transform.TransformerExceptionConstruct an XPath object.(Needs review -sc) This method initializes an XPathParser/ Compiler and compiles the expression.
-
XPath
public XPath(Expression expr)
Construct an XPath object.- Parameters:
expr- The Expression object.
-
-
Method Detail
-
initFunctionTable
private void initFunctionTable()
initial the function table
-
getLocator
public javax.xml.transform.SourceLocator getLocator()
Get the SourceLocator on the expression object.- Returns:
- the SourceLocator on the expression object, which may be null.
-
execute
public XObject execute(XPathContext xctxt, org.w3c.dom.Node contextNode, PrefixResolver namespaceContext) throws javax.xml.transform.TransformerException
Given an expression and a context, evaluate the XPath and return the result.- Parameters:
xctxt- The execution context.contextNode- The node that "." expresses.namespaceContext- The context in which namespaces in the XPath are supposed to be expanded.- Returns:
- The result of the XPath or null if callbacks are used.
- Throws:
javax.xml.transform.TransformerException- thrown if the error condition is severe enough to halt processing.javax.xml.transform.TransformerException- in case of error
-
execute
public XObject execute(XPathContext xctxt, int contextNode, PrefixResolver namespaceContext) throws javax.xml.transform.TransformerException
Given an expression and a context, evaluate the XPath and return the result.- Parameters:
xctxt- The execution context.contextNode- The node that "." expresses.namespaceContext- The context in which namespaces in the XPath are supposed to be expanded.- Throws:
javax.xml.transform.TransformerException- thrown if the active ProblemListener decides the error condition is severe enough to halt processing.javax.xml.transform.TransformerException- in case of error
-
error
public void error(XPathContext xctxt, java.lang.String msg, java.lang.Object[] args) throws javax.xml.transform.TransformerException
Tell the user of an error, and probably throw an exception.- Parameters:
xctxt- The XPath runtime context.msg- An error msgkey that corresponds to one of the constants found inXPATHErrorResources, which is a key for a format string.args- An array of arguments represented in the format string, which may be null.- Throws:
javax.xml.transform.TransformerException- if the current ErrorListoner determines to throw an exception.
-
callVisitors
public void callVisitors(XPathVisitor visitor)
This will traverse the heararchy, calling the visitor for each member. If the called visitor method returns false, the subtree should not be called.- Parameters:
visitor- The visitor whose appropriate method will be called.
-
-