Package com.helger.xml.xpath
Class XPathHelper
java.lang.Object
com.helger.xml.xpath.XPathHelper
Utility class to create
XPath and XPathExpression objects
more easily.- Author:
- Philip Helger
-
Method Summary
Modifier and TypeMethodDescriptionstatic XPathCreate a newXPathwithout any special settings using the defaultXPathFactory.static XPathcreateNewXPath(NamespaceContext aNamespaceContext) Create a newXPathwith the passed namespace context using the defaultXPathFactory.static XPathcreateNewXPath(XPathFactory aXPathFactory) Create a newXPathwithout any special settings.static XPathcreateNewXPath(XPathFactory aXPathFactory, NamespaceContext aNamespaceContext) Create a newXPathwith the passed namespace context.static XPathcreateNewXPath(XPathFactory aXPathFactory, XPathFunctionResolver aFunctionResolver) Create a newXPathwith the passed function resolver.static XPathcreateNewXPath(XPathFactory aXPathFactory, XPathVariableResolver aVariableResolver) Create a newXPathwith the passed variable resolver.static XPathcreateNewXPath(XPathFactory aXPathFactory, XPathVariableResolver aVariableResolver, XPathFunctionResolver aFunctionResolver, NamespaceContext aNamespaceContext) Create a newXPathwith the passed variable resolver, function resolver and namespace context.static XPathcreateNewXPath(XPathFunctionResolver aFunctionResolver) Create a newXPathwith the passed function resolver using the defaultXPathFactory.static XPathcreateNewXPath(XPathVariableResolver aVariableResolver) Create a newXPathwith the passed variable resolver using the defaultXPathFactory.static XPathcreateNewXPath(XPathVariableResolver aVariableResolver, NamespaceContext aNamespaceContext) Create a newXPathwith the passed variable resolver and namespace context using the defaultXPathFactory.static XPathcreateNewXPath(XPathVariableResolver aVariableResolver, XPathFunctionResolver aFunctionResolver, NamespaceContext aNamespaceContext) Create a newXPathwith the passed variable resolver, function resolver and namespace context using the defaultXPathFactory.static XPathExpressioncreateNewXPathExpression(String sXPath) Create a new XPath expression for evaluation using the defaultXPathFactory.static XPathExpressioncreateNewXPathExpression(NamespaceContext aNamespaceContext, String sXPath) Create a new XPath expression for evaluation using the defaultXPathFactory.static XPathExpressioncreateNewXPathExpression(XPathFunctionResolver aFunctionResolver, String sXPath) Create a new XPath expression for evaluation using the defaultXPathFactory.static XPathExpressioncreateNewXPathExpression(XPath aXPath, String sXPath) Create a new XPath expression for evaluation.static XPathExpressioncreateNewXPathExpression(XPathVariableResolver aVariableResolver, String sXPath) Create a new XPath expression for evaluation using the defaultXPathFactory.static XPathExpressioncreateNewXPathExpression(XPathVariableResolver aVariableResolver, XPathFunctionResolver aFunctionResolver, NamespaceContext aNamespaceContext, String sXPath) Create a new XPath expression for evaluation using the defaultXPathFactory.static XPathFactoryCreate a newXPathFactorytrying to instantiate Saxon classnet.sf.saxon.xpath.XPathFactoryImplfirst.static XPathFactory
-
Method Details
-
getDefaultXPathFactory
- Returns:
- The default XPath factory. Be careful when manipulating this
object! Never
null.
-
createXPathFactorySaxonFirst
Create a newXPathFactorytrying to instantiate Saxon classnet.sf.saxon.xpath.XPathFactoryImplfirst. If that fails, the default XPathFactory is created.- Returns:
- A new
XPathFactoryand nevernull. - Throws:
IllegalStateException- In case neither Saxon nor default factory could be instantiated!
-
createNewXPath
Create a newXPathwithout any special settings using the defaultXPathFactory.- Returns:
- The created non-
nullXPathobject
-
createNewXPath
Create a newXPathwithout any special settings.- Parameters:
aXPathFactory- The XPath factory object to use. May not benull.- Returns:
- The created non-
nullXPathobject
-
createNewXPath
Create a newXPathwith the passed variable resolver using the defaultXPathFactory.- Parameters:
aVariableResolver- Variable resolver to be used. May benull.- Returns:
- The created non-
nullXPathobject
-
createNewXPath
@Nonnull public static XPath createNewXPath(@Nonnull XPathFactory aXPathFactory, @Nullable XPathVariableResolver aVariableResolver) Create a newXPathwith the passed variable resolver.- Parameters:
aXPathFactory- The XPath factory object to use. May not benull.aVariableResolver- Variable resolver to be used. May benull.- Returns:
- The created non-
nullXPathobject
-
createNewXPath
Create a newXPathwith the passed function resolver using the defaultXPathFactory.- Parameters:
aFunctionResolver- Function resolver to be used. May benull.- Returns:
- The created non-
nullXPathobject
-
createNewXPath
@Nonnull public static XPath createNewXPath(@Nonnull XPathFactory aXPathFactory, @Nullable XPathFunctionResolver aFunctionResolver) Create a newXPathwith the passed function resolver.- Parameters:
aXPathFactory- The XPath factory object to use. May not benull.aFunctionResolver- Function resolver to be used. May benull.- Returns:
- The created non-
nullXPathobject
-
createNewXPath
Create a newXPathwith the passed namespace context using the defaultXPathFactory.- Parameters:
aNamespaceContext- Namespace context to be used. May benull.- Returns:
- The created non-
nullXPathobject
-
createNewXPath
@Nonnull public static XPath createNewXPath(@Nonnull XPathFactory aXPathFactory, @Nullable NamespaceContext aNamespaceContext) Create a newXPathwith the passed namespace context.- Parameters:
aXPathFactory- The XPath factory object to use. May not benull.aNamespaceContext- Namespace context to be used. May benull.- Returns:
- The created non-
nullXPathobject
-
createNewXPath
@Nonnull public static XPath createNewXPath(@Nullable XPathVariableResolver aVariableResolver, @Nullable NamespaceContext aNamespaceContext) Create a newXPathwith the passed variable resolver and namespace context using the defaultXPathFactory.- Parameters:
aVariableResolver- Variable resolver to be used. May benull.aNamespaceContext- Namespace context to be used. May benull.- Returns:
- The created non-
nullXPathobject
-
createNewXPath
@Nonnull public static XPath createNewXPath(@Nullable XPathVariableResolver aVariableResolver, @Nullable XPathFunctionResolver aFunctionResolver, @Nullable NamespaceContext aNamespaceContext) Create a newXPathwith the passed variable resolver, function resolver and namespace context using the defaultXPathFactory.- Parameters:
aVariableResolver- Variable resolver to be used. May benull.aFunctionResolver- Function resolver to be used. May benull.aNamespaceContext- Namespace context to be used. May benull.- Returns:
- The created non-
nullXPathobject
-
createNewXPath
@Nonnull public static XPath createNewXPath(@Nonnull XPathFactory aXPathFactory, @Nullable XPathVariableResolver aVariableResolver, @Nullable XPathFunctionResolver aFunctionResolver, @Nullable NamespaceContext aNamespaceContext) Create a newXPathwith the passed variable resolver, function resolver and namespace context.- Parameters:
aXPathFactory- The XPath factory object to use. May not benull.aVariableResolver- Variable resolver to be used. May benull.aFunctionResolver- Function resolver to be used. May benull.aNamespaceContext- Namespace context to be used. May benull.- Returns:
- The created non-
nullXPathobject
-
createNewXPathExpression
@Nonnull public static XPathExpression createNewXPathExpression(@Nullable XPathVariableResolver aVariableResolver, @Nullable XPathFunctionResolver aFunctionResolver, @Nullable NamespaceContext aNamespaceContext, @Nonnull @Nonempty String sXPath) Create a new XPath expression for evaluation using the defaultXPathFactory.- Parameters:
aVariableResolver- Variable resolver to be used. May benull.aFunctionResolver- Function resolver to be used. May benull.aNamespaceContext- Namespace context to be used. May benull.sXPath- The main XPath string to be evaluated- Returns:
- The
XPathExpressionobject to be used. - Throws:
IllegalArgumentException- if the XPath cannot be compiled
-
createNewXPathExpression
@Nonnull public static XPathExpression createNewXPathExpression(@Nullable XPathVariableResolver aVariableResolver, @Nonnull @Nonempty String sXPath) Create a new XPath expression for evaluation using the defaultXPathFactory.- Parameters:
aVariableResolver- Variable resolver to be used. May benull.sXPath- The main XPath string to be evaluated- Returns:
- The
XPathExpressionobject to be used. - Throws:
IllegalArgumentException- if the XPath cannot be compiled
-
createNewXPathExpression
@Nonnull public static XPathExpression createNewXPathExpression(@Nullable XPathFunctionResolver aFunctionResolver, @Nonnull @Nonempty String sXPath) Create a new XPath expression for evaluation using the defaultXPathFactory.- Parameters:
aFunctionResolver- Function resolver to be used. May benull.sXPath- The main XPath string to be evaluated- Returns:
- The
XPathExpressionobject to be used. - Throws:
IllegalArgumentException- if the XPath cannot be compiled
-
createNewXPathExpression
@Nonnull public static XPathExpression createNewXPathExpression(@Nullable NamespaceContext aNamespaceContext, @Nonnull @Nonempty String sXPath) Create a new XPath expression for evaluation using the defaultXPathFactory.- Parameters:
aNamespaceContext- Namespace context to be used. May benull.sXPath- The main XPath string to be evaluated- Returns:
- The
XPathExpressionobject to be used. - Throws:
IllegalArgumentException- if the XPath cannot be compiled
-
createNewXPathExpression
Create a new XPath expression for evaluation using the defaultXPathFactory.- Parameters:
sXPath- The main XPath string to be evaluated- Returns:
- The
XPathExpressionobject to be used. - Throws:
IllegalArgumentException- if the XPath cannot be compiled
-
createNewXPathExpression
@Nonnull public static XPathExpression createNewXPathExpression(@Nonnull XPath aXPath, @Nonnull @Nonempty String sXPath) Create a new XPath expression for evaluation.- Parameters:
aXPath- The pre-created XPath object. May not benull.sXPath- The main XPath string to be evaluated- Returns:
- The
XPathExpressionobject to be used. - Throws:
IllegalArgumentException- if the XPath cannot be compiled
-