Вы можете использовать этот слушатель:
import org.custommonkey.xmlunit.Difference;
import org.custommonkey.xmlunit.DifferenceConstants;
import org.custommonkey.xmlunit.DifferenceListener;
import org.w3c.dom.Node;
import java.util.HashSet;
import java.util.Set;
public class IgnoreChildrenOfNamedElementsDifferenceListener implements DifferenceListener {
public IgnoreChildrenOfNamedElementsDifferenceListener() {}
public int differenceFound(Difference difference) {
if (difference.getId() == DifferenceConstants.HAS_CHILD_NODES_ID ||
difference.getId() == DifferenceConstants.CHILD_NODELIST_LENGTH_ID ||
difference.getId() == DifferenceConstants.CHILD_NODE_NOT_FOUND_ID) {
return DifferenceListener.RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL;
}
}
return DifferenceListener.RETURN_ACCEPT_DIFFERENCE;
}
@Override
public void skippedComparison(Node control, Node test) {}
}
Тогда вы можете использовать его следующим образом:
Diff diff = new Diff(expectedDoc, obtainedDoc);
diff.overrideDifferenceListener(new IgnoreChildrenOfNamedElementsDifferenceListener("TestDateTime"));