Class SimpleXPathBasedCheck
java.lang.Object
org.sonarsource.analyzer.commons.xml.checks.SonarXmlCheck
org.sonarsource.analyzer.commons.xml.checks.SimpleXPathBasedCheck
-
Nested Class Summary
Nested classes/interfaces inherited from class org.sonarsource.analyzer.commons.xml.checks.SonarXmlCheck
SonarXmlCheck.Secondary -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionevaluate(XPathExpression expression, Node node) Evaluates a XPath expression on a given node from DOM.evaluateAsList(XPathExpression expression, Node node) Evaluates a XPath expression on a given node from DOM, returning it as a java List of Node, possibly empty.getXPathExpression(String expression) Compiles an XPath 1.0 expressionMethods inherited from class org.sonarsource.analyzer.commons.xml.checks.SonarXmlCheck
inputFile, reportIssue, reportIssue, reportIssueOnFile, ruleKey, scanFile, scanFile
-
Constructor Details
-
SimpleXPathBasedCheck
public SimpleXPathBasedCheck()
-
-
Method Details
-
getXPathExpression
Compiles an XPath 1.0 expression- Parameters:
expression- The expression to be compiled in XPath, as a String- Returns:
- The compiled expression
- Throws:
IllegalStateException- When the XPath expression can not be compiled by the XPath engine. Could occur with invalid expression, or incompatible XPath version.
-
evaluate
Evaluates a XPath expression on a given node from DOM. The only situation where null is returned is when XPath fails to evaluate the expression. This could occur with strangely built DOM. Note that in such case, the check will log extra information if the debug level is set.- Parameters:
expression- The XPath expression to be used, preferably compiled usinggetXPathExpression(String)node- The node to use as starting point of the XPath expression- Returns:
- The list of nodes, possibly empty, matching the XPath expression. Note that it will return null only when XPath fails to evaluate the expression.
-
evaluateAsList
Evaluates a XPath expression on a given node from DOM, returning it as a java List of Node, possibly empty.- Parameters:
expression- The XPath expression to be used, preferably compiled usinggetXPathExpression(String)node- The node to use as starting point of the XPath expression- Returns:
- The list of nodes, possibly empty, matching the XPath expression.
-