The list of methods to do XML Node Compare are organized into topic(s).
boolean
compare(Node n1, Node n2) Compares two DOM nodes for (deep) equality.
boolean ret = true;
ret &= n1.getLocalName().equals(n2.getLocalName());
ret &= n1.getNamespaceURI().equals(n2.getNamespaceURI());
String text = n1.getTextContent();
if (text != null) {
ret &= text.equals(n2.getTextContent());
NodeList children = n1.getChildNodes();
...
boolean
compareNode(Node nQ, Node nN, Boolean considerLength, Map qvars) compare Node
if (qvars == null) {
throw new Exception("qvars array must not be null");
if (nQ.hasChildNodes()) {
int nQChildLength = nQ.getChildNodes().getLength();
if (nN.hasChildNodes() && (!considerLength || nQChildLength == nN.getChildNodes().getLength())) {
for (int i = 0; i < nQChildLength; i++) {
if (!compareNode(nQ.getChildNodes().item(i), nN.getChildNodes().item(i), considerLength,
...
void
compareNodes(Node expected, Node actual) compare Nodes
if (expected.getNodeType() != actual.getNodeType()) {
throw new Exception("Different types of nodes: " + expected + " " + actual);
if (expected instanceof Document) {
Document expectedDoc = (Document) expected;
Document actualDoc = (Document) actual;
compareNodes(expectedDoc.getDocumentElement(), actualDoc.getDocumentElement());
} else if (expected instanceof Element) {
...
boolean
compareStringNode(Node node, String tag) Checks if a node resembles the given XML tag (including attributes).
if (tag.indexOf(node.getNodeName()) == -1)
return false;
NamedNodeMap attributes = node.getAttributes();
if (attributes != null) {
for (int i = 0; i < attributes.getLength(); i++) {
if (tag.indexOf(attributes.item(i).getNodeName()) == -1)
return false;
if (tag.indexOf(attributes.item(i).getNodeValue()) == -1)
...
boolean
compareTwoNodes(Node m, Node n) compare Two Nodes
return nodesAreEqual(m.getLocalName(), n.getLocalName()) && nodesAreEqual(m.getPrefix(), n.getPrefix());
boolean
equalNode(Node nodeA, Node nodeB) equal Node
if (nodeA == null) {
if (nodeB == null) {
return true;
return false;
if (nodeA.getNodeType() != nodeB.getNodeType()) {
return false;
...
boolean
equals(Node n1, Node n2) equals
if (!n1.getNodeName().equals(n2.getNodeName()))
return false;
NamedNodeMap nnm1 = n1.getAttributes();
NamedNodeMap nnm2 = n2.getAttributes();
if (nnm1.getLength() != nnm2.getLength())
return false;
for (int i = 0; i < nnm1.getLength(); i++) {
Node attr1 = nnm1.item(i);
...
boolean
isDescendant(Node testNode, Node compareToNode) is Descendant
if (testNode != null && compareToNode != null) {
while (testNode.getParentNode() != null) {
if (testNode.getParentNode() == compareToNode) {
return true;
testNode = testNode.getParentNode();
return false;