Package org.citrusframework.xml.xpath
Class XPathUtils
java.lang.Object
org.citrusframework.xml.xpath.XPathUtils
XPath utility class providing static utility methods
dealing with XPath expression evaluation.
Class is abstract to prevent instantiation.
- Author:
- Christoph Deppisch
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic Objectevaluate(Node node, String xPathExpression, NamespaceContext nsContext, XPathExpressionResult resultType) Evaluate XPath expression as String result type regardless what actual result type the expression will evaluate to.static BooleanevaluateAsBoolean(Node node, String xPathExpression, NamespaceContext nsContext) Evaluate XPath expression with result type Boolean value.static NodeevaluateAsNode(Node node, String xPathExpression, NamespaceContext nsContext) Evaluate XPath expression with result type Node.static NodeListevaluateAsNodeList(Node node, String xPathExpression, NamespaceContext nsContext) Evaluate XPath expression with result type NodeList.static DoubleevaluateAsNumber(Node node, String xPathExpression, NamespaceContext nsContext) Evaluate XPath expression with result type Number.static ObjectevaluateAsObject(Node node, String xPathExpression, NamespaceContext nsContext, QName resultType) Evaluate XPath expression.static StringevaluateAsString(Node node, String xPathExpression, NamespaceContext nsContext) Evaluate XPath expression with result type String.static ObjectevaluateExpression(Node node, String xPathExpression, NamespaceContext nsContext, QName returnType) Evaluates the expression.getDynamicNamespaces(String expression) Extracts dynamic namespaces that are inline inside a XPath expression.static booleanhasDynamicNamespaces(String expression) Searches for dynamic namespaces in expression.static booleanisXPathExpression(String expression) Method to find out whether an expression is of XPath nature or custom dot notation syntax.static StringreplaceDynamicNamespaces(String expression, Map<String, String> namespaces) Replaces all dynamic namespaces in a XPath expression with respective prefixes in namespace map.
-
Field Details
-
DYNAMIC_NS_START
Dynamic namespace prefix suffix- See Also:
-
DYNAMIC_NS_END
- See Also:
-
-
Method Details
-
getDynamicNamespaces
Extracts dynamic namespaces that are inline inside a XPath expression. Example:/{http://sample.org/foo}foo/{http://sample.org/bar}bar- Parameters:
expression-- Returns:
-
replaceDynamicNamespaces
Replaces all dynamic namespaces in a XPath expression with respective prefixes in namespace map. XPath:/{http://sample.org/foo}foo/{http://sample.org/bar}barresults in/ns1:foo/ns2:barwhere the namespace map contains ns1 and ns2.- Parameters:
expression-namespaces-- Returns:
-
hasDynamicNamespaces
Searches for dynamic namespaces in expression.- Parameters:
expression-- Returns:
-
evaluate
public static Object evaluate(Node node, String xPathExpression, NamespaceContext nsContext, XPathExpressionResult resultType) Evaluate XPath expression as String result type regardless what actual result type the expression will evaluate to.- Parameters:
node-xPathExpression-nsContext-resultType-- Returns:
-
evaluateAsNode
Evaluate XPath expression with result type Node.- Parameters:
node-xPathExpression-nsContext-- Returns:
-
evaluateAsNodeList
public static NodeList evaluateAsNodeList(Node node, String xPathExpression, NamespaceContext nsContext) Evaluate XPath expression with result type NodeList.- Parameters:
node-xPathExpression-nsContext-- Returns:
-
evaluateAsString
public static String evaluateAsString(Node node, String xPathExpression, NamespaceContext nsContext) Evaluate XPath expression with result type String.- Parameters:
node-xPathExpression-nsContext-- Returns:
-
evaluateAsBoolean
public static Boolean evaluateAsBoolean(Node node, String xPathExpression, NamespaceContext nsContext) Evaluate XPath expression with result type Boolean value.- Parameters:
node-xPathExpression-nsContext-- Returns:
-
evaluateAsNumber
public static Double evaluateAsNumber(Node node, String xPathExpression, NamespaceContext nsContext) Evaluate XPath expression with result type Number.- Parameters:
node-xPathExpression-nsContext-- Returns:
-
evaluateAsObject
public static Object evaluateAsObject(Node node, String xPathExpression, NamespaceContext nsContext, QName resultType) Evaluate XPath expression.- Parameters:
node-xPathExpression-nsContext-- Returns:
-
isXPathExpression
Method to find out whether an expression is of XPath nature or custom dot notation syntax.- Parameters:
expression- the expression string to check.- Returns:
- boolean the result.
-
evaluateExpression
public static Object evaluateExpression(Node node, String xPathExpression, NamespaceContext nsContext, QName returnType) Evaluates the expression.- Parameters:
node- the node.xPathExpression- the expression.nsContext- the context.returnType-- Returns:
- the result.
-