public class Diff extends Object implements DifferenceListener, ComparisonController
appendMessage
or toString methods. NB: When comparing documents, the
comparison is halted as soon as the status (identical / similar / different)
is known with certainty. For a list of all differences between the documents
an instance of the DetailedDiff class can be used
instead.RETURN_ACCEPT_DIFFERENCE, RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL, RETURN_IGNORE_DIFFERENCE_NODES_SIMILAR, RETURN_UPGRADE_DIFFERENCE_NODES_DIFFERENT| Modifier | Constructor and Description |
|---|---|
protected |
Diff(Diff prototype)
Construct a Diff from a prototypical instance.
|
|
Diff(Document controlDoc,
Document testDoc)
Construct a Diff that compares the XML in two Documents
|
|
Diff(Document controlDoc,
Document testDoc,
DifferenceEngineContract comparator)
Construct a Diff that compares the XML in two Documents using a specific
DifferenceEngine
|
|
Diff(Document controlDoc,
Document testDoc,
DifferenceEngineContract comparator,
ElementQualifier elementQualifier)
Construct a Diff that compares the XML in two Documents using a specific
DifferenceEngine and ElementQualifier
DifferenceEngine
|
|
Diff(DOMSource control,
DOMSource test)
Construct a Diff that compares the XML in two JAXP DOMSources
|
|
Diff(InputSource control,
InputSource test)
Construct a Diff that compares the XML read from two JAXP InputSources
|
|
Diff(Reader control,
Reader test)
Construct a Diff that compares the XML read from two Readers
|
|
Diff(String control,
String test)
Construct a Diff that compares the XML in two Strings
|
|
Diff(String control,
Transform testTransform)
Construct a Diff that compares the XML in a control Document against the
result of a transformation
|
| Modifier and Type | Method and Description |
|---|---|
StringBuffer |
appendMessage(StringBuffer toAppendTo)
Append the message from the result of this Diff instance to a specified
StringBuffer
|
protected void |
compare()
Top of the recursive comparison execution tree
|
int |
differenceFound(Difference difference)
DifferenceListener implementation.
|
int |
evaluate(Difference difference)
Evaluate the difference.
|
boolean |
haltComparison(Difference afterDifference)
ComparisonController implementation.
|
boolean |
identical()
Return the result of a comparison.
|
void |
overrideDifferenceListener(DifferenceListener delegate)
Override the
DifferenceListener used to determine how
to handle differences that are found. |
void |
overrideElementQualifier(ElementQualifier delegate)
Override the
ElementQualifier used to determine which
control and test nodes are comparable for this difference comparison. |
void |
overrideMatchTracker(MatchTracker delegate)
Override the
MatchTracker used to track
successfully matched nodes. |
boolean |
similar()
Return the result of a comparison.
|
void |
skippedComparison(Node control,
Node test)
DifferenceListener implementation.
|
String |
toString()
Get the result of this Diff instance as a String
Note: This method will perform the comparison and
cache the result if it hasn't been performed already.
|
public Diff(String control, String test) throws SAXException, IOException
control - the control XMLtest - the test XMLSAXException - if the parser feels like itIOException - on i/o errorspublic Diff(Reader control, Reader test) throws SAXException, IOException
control - the control XMLtest - the test XMLSAXException - if the parser feels like itIOException - on i/o errorspublic Diff(Document controlDoc, Document testDoc)
controlDoc - the control XMLtestDoc - the test XMLpublic Diff(String control, Transform testTransform) throws IOException, TransformerException, SAXException
control - the control XMLtestTransform - the test XMLSAXException - if the parser feels like itTransformerException - if the transformer feels like itIOException - on i/o errorspublic Diff(InputSource control, InputSource test) throws SAXException, IOException
control - the control XMLtest - the test XMLSAXException - if the parser feels like itIOException - on i/o errorspublic Diff(DOMSource control, DOMSource test)
control - the control XMLtest - the test XMLpublic Diff(Document controlDoc, Document testDoc, DifferenceEngineContract comparator)
controlDoc - the control XMLtestDoc - the test XMLcomparator - the difference enginepublic Diff(Document controlDoc, Document testDoc, DifferenceEngineContract comparator, ElementQualifier elementQualifier)
controlDoc - the control XMLtestDoc - the test XMLcomparator - the difference engineelementQualifier - the element qualifierprotected Diff(Diff prototype)
prototype - a prototypical instanceprotected final void compare()
public boolean similar()
public boolean identical()
public int differenceFound(Difference difference)
overrideDifferenceListener
method has been called then the interpretation of the difference
will be delegated.differenceFound in interface DifferenceListenerdifference - a Difference instance as defined in DifferenceConstants describing the cause
of the difference and containing the detail of the nodes that
differpublic int evaluate(Difference difference)
difference - the differencepublic void skippedComparison(Node control, Node test)
overrideDifferenceListener
method has been called then the call will be delegated
otherwise a message is printed to System.err.skippedComparison in interface DifferenceListenercontrol - the control node being comparedtest - the test node being comparedDifferenceEnginepublic boolean haltComparison(Difference afterDifference)
haltComparison in interface ComparisonControllerafterDifference - the last Difference passed to differenceFoundDifference.isRecoverable()public StringBuffer appendMessage(StringBuffer toAppendTo)
toAppendTo - buffer to append messages topublic String toString()
Note: This method will perform the comparison and cache the result if it hasn't been performed already. Any configuration changes made after calling this method will be ignored.
public void overrideDifferenceListener(DifferenceListener delegate)
DifferenceListener used to determine how
to handle differences that are found.delegate - the DifferenceListener instance to delegate handling to.public void overrideElementQualifier(ElementQualifier delegate)
ElementQualifier used to determine which
control and test nodes are comparable for this difference comparison.delegate - the ElementQualifier instance to delegate to.public void overrideMatchTracker(MatchTracker delegate)
MatchTracker used to track
successfully matched nodes.delegate - the MatchTracker instance to delegate handling to.Copyright © 2001–2025 XMLUnit. All rights reserved.