org.custommonkey.xmlunit

Class Diff

public class Diff extends Object implements DifferenceListener, ComparisonController

Compares and describes any difference between XML documents. Two documents are either:

The difference between compared documents is contained in a message buffer held in this class, accessible either through the 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.
Examples and more at xmlunit.sourceforge.net
Constructor Summary
Diff(String control, String test)
Construct a Diff that compares the XML in two Strings
Diff(Reader control, Reader test)
Construct a Diff that compares the XML read from two Readers
Diff(Document controlDoc, Document testDoc)
Construct a Diff that compares the XML in two Documents
Diff(String control, Transform testTransform)
Construct a Diff that compares the XML in a control Document against the result of a transformation
Diff(InputSource control, InputSource test)
Construct a Diff that compares the XML read from two JAXP InputSources
Diff(DOMSource control, DOMSource test)
Construct a Diff that compares the XML in two JAXP DOMSources
Diff(Document controlDoc, Document testDoc, DifferenceEngine comparator)
Construct a Diff that compares the XML in two Documents using a specific DifferenceEngine
Diff(Document controlDoc, Document testDoc, DifferenceEngine comparator, ElementQualifier elementQualifier)
Construct a Diff that compares the XML in two Documents using a specific DifferenceEngine and ElementQualifier
protected Diff(Diff prototype)
Construct a Diff from a prototypical instance.
Method Summary
StringBufferappendMessage(StringBuffer toAppendTo)
Append the message from the result of this Diff instance to a specified StringBuffer
protected voidcompare()
Top of the recursive comparison execution tree
intdifferenceFound(Difference difference)
DifferenceListener implementation.
booleanhaltComparison(Difference afterDifference)
ComparisonController implementation.
booleanidentical()
Return the result of a comparison.
voidoverrideDifferenceListener(DifferenceListener delegate)
Override the DifferenceListener used to determine how to handle differences that are found.
voidoverrideElementQualifier(ElementQualifier delegate)
Override the ElementQualifier used to determine which control and test nodes are comparable for this difference comparison.
booleansimilar()
Return the result of a comparison.
voidskippedComparison(Node control, Node test)
DifferenceListener implementation.
StringtoString()
Get the result of this Diff instance as a String

Constructor Detail

Diff

public Diff(String control, String test)
Construct a Diff that compares the XML in two Strings

Diff

public Diff(Reader control, Reader test)
Construct a Diff that compares the XML read from two Readers

Diff

public Diff(Document controlDoc, Document testDoc)
Construct a Diff that compares the XML in two Documents

Diff

public Diff(String control, Transform testTransform)
Construct a Diff that compares the XML in a control Document against the result of a transformation

Diff

public Diff(InputSource control, InputSource test)
Construct a Diff that compares the XML read from two JAXP InputSources

Diff

public Diff(DOMSource control, DOMSource test)
Construct a Diff that compares the XML in two JAXP DOMSources

Diff

public Diff(Document controlDoc, Document testDoc, DifferenceEngine comparator)
Construct a Diff that compares the XML in two Documents using a specific DifferenceEngine

Diff

public Diff(Document controlDoc, Document testDoc, DifferenceEngine comparator, ElementQualifier elementQualifier)
Construct a Diff that compares the XML in two Documents using a specific DifferenceEngine and ElementQualifier

Diff

protected Diff(Diff prototype)
Construct a Diff from a prototypical instance. Used by extension subclasses

Parameters: prototype a prototypical instance

Method Detail

appendMessage

public StringBuffer appendMessage(StringBuffer toAppendTo)
Append the message from the result of this Diff instance to a specified StringBuffer

Parameters: toAppendTo

Returns: specified StringBuffer with message appended

compare

protected final void compare()
Top of the recursive comparison execution tree

differenceFound

public int differenceFound(Difference difference)
DifferenceListener implementation. If the overrideDifferenceListener method has been called then the interpretation of the difference will be delegated.

Parameters: difference

Returns: a DifferenceListener.RETURN_... constant indicating how the difference was interpreted. Always RETURN_ACCEPT_DIFFERENCE if the call is not delegated.

haltComparison

public boolean haltComparison(Difference afterDifference)
ComparisonController implementation.

Parameters: afterDifference

Returns: true if the difference is not recoverable and the comparison should be halted, or false if the difference is recoverable and the comparison can continue

identical

public boolean identical()
Return the result of a comparison. Two documents are considered to be "identical" if they contain the same elements and attributes in the same order.

overrideDifferenceListener

public void overrideDifferenceListener(DifferenceListener delegate)
Override the DifferenceListener used to determine how to handle differences that are found.

Parameters: delegate the DifferenceListener instance to delegate handling to.

overrideElementQualifier

public void overrideElementQualifier(ElementQualifier delegate)
Override the ElementQualifier used to determine which control and test nodes are comparable for this difference comparison.

Parameters: delegate the ElementQualifier instance to delegate to.

similar

public boolean similar()
Return the result of a comparison. Two documents are considered to be "similar" if they contain the same elements and attributes regardless of order.

skippedComparison

public void skippedComparison(Node control, Node test)
DifferenceListener implementation. If the overrideDifferenceListener method has been called then the call will be delegated otherwise a message is printed to System.err.

Parameters: control test

toString

public String toString()
Get the result of this Diff instance as a String

Returns: result of this Diff