/** * Construct a Diff that compares the XML in two Documents using a specific * DifferenceEngine */ public Diff(Document controlDoc, Document testDoc, DifferenceEngine comparator) { this(controlDoc, testDoc, comparator, new ElementNameQualifier()); }
@Override public boolean qualifyForComparison(Element control, Element test) { if (control == null || test == null) { return super.qualifyForComparison(control, test); } if (control.getNodeName().equals("entry") && test.getNodeName().equals("entry")) { String controlKeyName = control.getElementsByTagName("key").item(0).getTextContent(); String testKeyName = test.getElementsByTagName("key").item(0).getTextContent(); return controlKeyName.equals(testKeyName); } return super.qualifyForComparison(control, test); } });
/** * Determine whether two elements qualify for further Difference comparison. * @param control * @param test * @return true if the two elements qualify for further comparison based on * their similar namespace URI and non-namespaced tag name, * false otherwise */ public boolean qualifyForComparison(Element control, Element test) { return control != null && test !=null && equalsNamespace(control, test) && getNonNamespacedNodeName(control).equals(getNonNamespacedNodeName(test)); } /**
/** * Determine whether two elements qualify for further Difference comparison. * @param differenceEngine the DifferenceEngine instance wanting to * determine if the elements are comparable * @param control * @param test * @return true if the two elements qualify for further comparison based on * both the superclass qualification (namespace URI and non- namespaced tag * name), and the presence of qualifying attributes with the same values; * false otherwise */ public boolean qualifyForComparison(Element control, Element test) { if (super.qualifyForComparison(control, test)) { return areAttributesComparable(control, test); } return false; }
/** * Construct a Diff that compares the XML in two Documents using a specific * DifferenceEngine */ public Diff(Document controlDoc, Document testDoc, DifferenceEngineContract comparator) { this(controlDoc, testDoc, comparator, new ElementNameQualifier()); }
stillSimilar = NAME_QUALIFIER.qualifyForComparison(currentControl, currentTest);
if (!NAME_QUALIFIER.qualifyForComparison((Element) currentControl, (Element) currentTest)) { return false;
/** * Determine whether two elements qualify for further Difference comparison. * @param control * @param test * @return true if the two elements qualify for further comparison based on * both the superclass qualification (namespace URI and non- namespaced tag * name), and the qualification of the text nodes contained within the * elements; false otherwise */ public boolean qualifyForComparison(Element control, Element test) { if (super.qualifyForComparison(control, test)) { return similar(extractText(control), extractText(test)); } return false; }