public class XPathDifferenceHandler extends DifferenceHandler
DifferenceListener which ignores the Difference if the XPath of the node was added to ignorable
expressions using ignoreDifference(String). Multiple XPath expressions can be added to the ignore list by
calling ignoreDifference(String). Note that these expressions must be the complete absolute XPath location
starting from the document root.Difference.getControlNodeDetail(),
Difference.getTestNodeDetail(),
NodeDetail.getXpathLocation()| Constructor and Description |
|---|
XPathDifferenceHandler()
Delegates to
XPathDifferenceHandler(boolean) with stripPositions = true. |
XPathDifferenceHandler(boolean stripPositions)
Creates a new
XPathDifferenceHandler. |
| Modifier and Type | Method and Description |
|---|---|
void |
addDifferenceListener(String xpath,
org.custommonkey.xmlunit.DifferenceListener differenceListener)
Registers a custom
DifferenceListener for the given XPath expression |
int |
differenceFound(org.custommonkey.xmlunit.Difference difference) |
void |
ignoreDifference(String xpath)
Ignore the
Difference with the given XPath expression |
skippedComparisonpublic XPathDifferenceHandler(boolean stripPositions)
XPathDifferenceHandler.
If there is a difference you want to ignore at the following XPath location
/datasource/data/selection[2]/option[4]you can achieve this by either setting up your
XPathDifferenceHandler like this
DifferenceHandler differenceHandler = new XPathDifferenceHandler(true);
differenceHandler.ignoreDifference("/datasource/data/selection/option");
or this
DifferenceHandler differenceHandler = new XPathDifferenceHandler(false);
differenceHandler.ignoreDifference("/datasource/data/selection[2]/option[4]");
In the first case, with stripPositions = true, you can omit the positions from the expression. As a side
effect, every Difference with the (stripped) XPath of /datasource/data/selection/option will be
ignored.Difference.
stripPositions - whether or not to strip the positions from the actual XPath of the Difference
before checking the registry for an appropriate DifferenceListenerpublic XPathDifferenceHandler()
XPathDifferenceHandler(boolean) with stripPositions = true.XPathDifferenceHandler(boolean)public void ignoreDifference(String xpath)
Difference with the given XPath expressionxpath - the XPath expression. Note that this must be the complete absolute XPath location starting from the
document root.public void addDifferenceListener(String xpath, org.custommonkey.xmlunit.DifferenceListener differenceListener)
DifferenceListener for the given XPath expressionxpath - the XPath expression. Note that this must be the complete absolute XPath location
starting from the document root.differenceListener - the DifferenceListener to registerpublic int differenceFound(org.custommonkey.xmlunit.Difference difference)
differenceFound in interface org.custommonkey.xmlunit.DifferenceListenerdifferenceFound in class DifferenceHandlerCopyright © 2011–2023 aiticon GmbH. All rights reserved.