ВУЗ: Не указан
Категория: Не указан
Дисциплина: Не указана
Добавлен: 02.01.2026
Просмотров: 491
Скачиваний: 0
XMLUnit Java User’s Guide |
14 / 35 |
ID |
Constant |
recoverable |
Description |
|
ELEMENT_TAG_NAME |
|
|
The two pieces of XML |
|
ELEMENT_TAG_NAME |
false |
contain elements with |
||
_ID |
||||
|
|
different tag names. |
||
|
|
|
||
|
|
|
The two pieces of XML |
|
ELEMENT_NUM_ATTRIB |
ELEMENT_NUM_ATTRIB |
false |
contain a common element, |
|
UTES_ID |
UTES |
but the number of attributes |
||
|
||||
|
|
|
on the element is different. |
|
|
|
|
An element in one piece of |
|
HAS_CHILD_NODES_ID |
HAS_CHILD_NODES |
false |
XML has child nodes while |
|
the corresponding one in |
||||
|
|
|
||
|
|
|
the other has not. |
|
CHILD_NODELIST_LEN |
CHILD_NODELIST_LEN |
|
Two elements in the two |
|
false |
pieces of XML differ by |
|||
GTH_ID |
GTH |
|||
|
their number of child nodes. |
|||
|
|
|
||
|
|
|
Two elements in the two |
|
CHILD_NODELIST_SEQ |
CHILD_NODELIST_SEQ |
true |
pieces of XML contain the |
|
UENCE_ID |
UENCE |
same child nodes but in a |
||
|
||||
|
|
|
different order. |
|
|
|
|
A child node in one piece of |
|
CHILD_NODE_NOT_FOU |
CHILD_NODE_NOT_FO |
false |
XML couldn’t be matched |
|
ND_ID |
UND |
against any other node of |
||
|
||||
|
|
|
the other piece. |
|
|
|
|
The attributes on an element |
|
ATTR_SEQUENCE_ID |
ATTR_SEQUENCE |
true |
appear in different order7 in |
|
|
|
|
the two pieces of XML. |
Table 2: Element level Differences detected by DifferenceEngine
ID |
Constant |
recoverable |
Description |
|
|
|
|
An attribute that has a |
|
|
|
|
default value according to |
|
ATTR_VALUE_EXPLICI |
ATTR_VALUE_EXPLICI |
|
the content model of the |
|
true |
element in question has |
|||
TLY_SPECIFIED_ID |
TLY_SPECIFIED |
|||
|
been specified explicitly in |
|||
|
|
|
||
|
|
|
one piece of XML but not |
|
|
|
|
in the other.8 |
|
ATTR_NAME_NOT_FOUN |
ATTR_NAME_NOT_FO |
|
One piece of XML contains |
|
false |
an attribute on an element |
|||
D_ID |
UND |
|||
|
that is missing in the other. |
|||
|
|
|
||
|
|
|
The value of an element’s |
|
ATTR_VALUE_ID |
ATTR_VALUE |
false |
attribute is different in the |
|
|
|
|
two pieces of XML. |
Table 3: Attribute level Differences detected by DifferenceEngine
XMLUnit Java User’s Guide |
|
|
15 / 35 |
||
|
|
|
|
|
|
|
ID |
Constant |
recoverable |
Description |
|
|
|
|
|
The content of two |
|
|
COMMENT_VALUE_ID |
COMMENT_VALUE |
false |
comments is different in the |
|
|
|
|
|
two pieces of XML. |
|
|
|
|
|
The target of two |
|
|
PROCESSING_INSTRUC |
PROCESSING_INSTRUC |
false |
processing instructions is |
|
|
TION_TARGET_ID |
TION_TARGET |
different in the two pieces |
|
|
|
|
|
|||
|
|
|
|
of XML. |
|
|
PROCESSING_INSTRUC |
PROCESSING_INSTRUC |
|
The data of two processing |
|
|
false |
instructions is different in |
|
||
|
TION_DATA_ID |
TION_DATA |
|
||
|
|
the two pieces of XML. |
|
||
|
|
|
|
|
|
|
|
|
|
The content of two CDATA |
|
|
CDATA_VALUE_ID |
CDATA_VALUE |
false |
sections is different in the |
|
|
|
|
|
two pieces of XML. |
|
|
|
|
|
The value of two texts is |
|
|
TEXT_VALUE_ID |
TEXT_VALUE |
false |
different in the two pieces |
|
|
|
|
|
of XML. |
|
Table 4: Other Differences detected by DifferenceEngine
Difference.getId() |
NodeDetail.getValue() |
|
HAS_DOCTYPE_DECLARATION_ID |
"not null" if the document has a DOCTYPE |
|
declaration, "null" otherwise. |
||
|
||
DOCTYPE_NAME_ID |
The name of the root element. |
|
DOCTYPE_PUBLIC_ID |
The PUBLIC identifier. |
|
DOCTYPE_SYSTEM_ID |
The SYSTEM identifier. |
|
|
If one node was absent: "not null" if the node exists, |
|
NODE_TYPE_ID |
"null" otherwise. If the node types differ the value will |
|
be a string-ified version of org.w3c.dom.Node. |
||
|
||
|
getNodeType(). |
|
NAMESPACE_PREFIX_ID |
The Namespace prefix. |
|
NAMESPACE_URI_ID |
The Namespace URI. |
|
SCHEMA_LOCATION_ID |
The attribute’s value or "[attribute absent]" if it has not |
|
been specified. |
||
|
||
NO_NAMESPACE_SCHEMA_LOCATION_ID |
The attribute’s value or "[attribute absent]" if it has not |
|
been specified. |
||
|
||
ELEMENT_TAG_NAME_ID |
The tag name with any Namespace information stripped. |
|
ELEMENT_NUM_ATTRIBUTES_ID |
The number of attributes present turned into a String. |
|
HAS_CHILD_NODES_ID |
"true" if the element has child nodes, "false" |
|
otherwise. |
||
|
||
CHILD_NODELIST_LENGTH_ID |
The number of child nodes present turned into a String. |
|
CHILD_NODELIST_SEQUENCE_ID |
The sequence number of this child node turned into a |
|
String. |
||
|
||
CHILD_NODE_NOT_FOUND_ID |
The name of the unmatched node or null. |
|
ATTR_SEQUENCE_ID |
The attribute’s name. |
|
ATTR_VALUE_EXPLICITLY_SPECIFIED_ID |
"true" if the attribute has been specified, "false" |
|
otherwise. |
||
|
||
ATTR_NAME_NOT_FOUND_ID |
The attribute’s name or null. |
|
ATTR_VALUE_ID |
The attribute’s value. |
|
COMMENT_VALUE_ID |
The actual comment. |
|
PROCESSING_INSTRUCTION_TARGET_ID |
The processing instruction’s target. |
|
PROCESSING_INSTRUCTION_DATA_ID |
The processing instruction’s data. |
|
CDATA_VALUE_ID |
The content of the CDATA section. |
|
TEXT_VALUE_ID |
The actual text. |
Table 5: Contents of NodeDetail.getValue() for Differences
XMLUnit Java User’s Guide |
16 / 35 |
Whenever a difference has been detected by the DifferenceEngine the haltComparison method will be called immediately after the DifferenceListener has been informed of the difference. This is true no matter what type of Difference has been found or which value the DifferenceListener has returned.
The only implementations of ComparisonController that ship with XMLUnit are Diff and DetailedDiff, see Section 3.5 for details about them.
A ComparisonController that halted the comparison on any non-recoverable difference could be implemented as:
Example 3.2 A Simple ComparisonController
public class HaltOnNonRecoverable implements ComparisonController {
public boolean haltComparison(Difference afterDifference) {
return !afterDifference.isRecoverable();
}
}
3.3 DifferenceListener
DifferenceListener contains two callback methods that are invoked by the DifferenceEngine when differences are detected:
/**
*Receive notification that 2 nodes are different.
*@param difference a Difference instance as defined in {@link
*DifferenceConstants DifferenceConstants} describing the cause
*of the difference and containing the detail of the nodes that
*differ
*@return int one of the RETURN_... constants describing how this
*difference was interpreted
*/
int differenceFound(Difference difference);
/**
*Receive notification that a comparison between 2 nodes has been skipped
*because the node types are not comparable by the DifferenceEngine
*@param control the control node being compared
*@param test the test node being compared
*@see DifferenceEngine
*/
void skippedComparison(Node control, Node test);
differenceFound is invoked by DifferenceEngine as soon as a difference has been detected. The return value of that method is completely ignored by DifferenceEngine, it becomes important when used together with Diff, though (see Section 3.5). The return value should be one of the four constants defined in the the DifferenceListener interface:
/**
*Standard return value for the <code>differenceFound</code> method.
*Indicates that the <code>Difference</code> is interpreted as defined
*in {@link DifferenceConstants DifferenceConstants}.
*/
int RETURN_ACCEPT_DIFFERENCE; /**
*Override return value for the <code>differenceFound</code> method.
*Indicates that the nodes identified as being different should be
*interpreted as being identical.
*/
int RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL; /**
* Override return value for the <code>differenceFound</code> method.