/** * Prints error description text. The generated text include position * information from both documents. * * @param msg error message text */ protected void printError(String msg) { if (m_differencePrint != null) { m_differencePrint.println(msg + " - from " + buildPositionString(m_parserA) + " to " + buildPositionString(m_parserB)); } }
/** * Check if two text strings match, ignoring leading and trailing spaces. * Any mismatch is printed immediately, with the supplied lead text. * * @param texta String to compare * @param textb String to compare * @param lead error text lead * @return <code>true</code> if the texts match, <code>false</code> if * not */ protected boolean matchText(String texta, String textb, String lead) { if (equalValues(texta, textb)) { return true; } else if (!m_schemaCompare && texta.trim().equals(textb.trim())) { return true; } else { printError(lead); if (m_differencePrint != null) { m_differencePrint.println(" \"" + texta + "\" (length " + texta.length() + " vs. \"" + textb + "\" (length " + textb.length() + ')'); } return false; } }
InputStreamReader frdr = new InputStreamReader (new FileInputStream(fout), encoding); DocumentComparator comp = new DocumentComparator(System.err); if (comp.compare(frdr, brdr)) { return true; } else {
int typeb = m_parserB.getEventType(); if (typea != typeb) { printError("Different document structure"); return false; } else if (typea == XmlPullParser.START_TAG) { if (!matchNames()) { printError("Different start tags"); return false; } else { if (!matchAttributes()) { same = false; if (!matchText(texta, textb, "Different text content between elements")) { same = false; if (!matchNames()) { printError("Different end tags"); return false; if (!matchText(texta, textb, "Different text content")) { same = false; if (!matchText(texta, textb, "Different text content between elements")) { same = false;
ns.equals(m_parserB.getAttributeNamespace(j))) { flags[j] = true; if (!equalValues(value, m_parserB.getAttributeValue(j))) { if (match) { printError("Attribute mismatch"); match = false; buildName(ns, name) + " value '" + value + "' != '" + m_parserB.getAttributeValue(j) + '\''); if (!found && !(m_schemaCompare && isSchemaLocation(name, ns))) { if (match) { printError("Attribute mismatch"); match = false; buildName(ns, name) + "=\"" + value + "\" is missing from second document"); String ns = m_parserB.getAttributeNamespace(i); String name = m_parserB.getAttributeName(i); if (!m_schemaCompare || !isSchemaLocation(name, ns)) { if (match) { printError("Attribute mismatch"); match = false; buildName(ns, name) + " is missing from first document");
return normalizeDecimal(trima).equals(normalizeDecimal(trimb)); } else { return false;
ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream pstream = new PrintStream(baos); DocumentComparator comp = new DocumentComparator(pstream); if (comp.compare(frdr, brdr)) {