Skip to content

Instantly share code, notes, and snippets.

@MichaH
Created October 29, 2014 16:51
Show Gist options
  • Save MichaH/77344cf2bbe9ba3f81af to your computer and use it in GitHub Desktop.
Save MichaH/77344cf2bbe9ba3f81af to your computer and use it in GitHub Desktop.
A diff for two XML-InputStreams
private static boolean isSameXMLContent(InputStream s1, InputStream s2)
throws ParserConfigurationException, SAXException, IOException {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
dbf.setCoalescing(true);
dbf.setIgnoringElementContentWhitespace(true);
dbf.setIgnoringComments(true);
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc1 = db.parse(s1);
doc1.normalizeDocument();
Document doc2 = db.parse(s2);
doc2.normalizeDocument();
return doc1.isEqualNode(doc2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment