I'm trying to implement the java program to compare two HTML files. I gone through a lot of sources in the internet, but everything is stops at one for me. That is I'm getting below exception
Exception in thread "main" java.lang.NullPointerException
at net.sf.saxon.event.ReceivingContentHandler.startElement(ReceivingContentHandler.java:279)
at org.outerj.daisy.diff.html.HtmlSaxDiffOutput.generateOutput(Unknown Source)
at org.outerj.daisy.diff.html.HTMLDiffer.diff(Unknown Source)
at com.interac.api.emt.noti.DaizyDiff.main(DaizyDiff.java:63)
My Full Code:
public class DaizyDiff {
static String html1 = "<html class='foobar'>Hello</html>";
static String html2 = "<html>Bye</html>";
public static void main(String args[]) throws TransformerConfigurationException, IOException, SAXException {
final StringWriter finalResult = new StringWriter();
final SAXTransformerFactory tf = (SAXTransformerFactory) TransformerFactory.newInstance();
final TransformerHandler result = tf.newTransformerHandler();
result.getTransformer().setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
result.getTransformer().setOutputProperty(OutputKeys.INDENT, "yes");
result.getTransformer().setOutputProperty(OutputKeys.METHOD, "html");
result.getTransformer().setOutputProperty(OutputKeys.ENCODING, "UTF-8");
result.setResult(new StreamResult(finalResult));
final ContentHandler postProcess = result;
final Locale locale = Locale.getDefault();
final String prefix = "diff";
final NekoHtmlParser cleaner = new NekoHtmlParser();
final InputSource oldSource = new InputSource(new StringReader(html1));
final InputSource newSource = new InputSource(new StringReader(html2));
final DomTreeBuilder oldHandler = new DomTreeBuilder();
cleaner.parse(oldSource, oldHandler);
final TextNodeComparator leftComparator = new TextNodeComparator(oldHandler, locale);
final DomTreeBuilder newHandler = new DomTreeBuilder();
cleaner.parse(newSource, newHandler);
final TextNodeComparator rightComparator = new TextNodeComparator(newHandler, locale);
final HtmlSaxDiffOutput output = new HtmlSaxDiffOutput(postProcess, prefix);
final HTMLDiffer differ = new HTMLDiffer(output);
differ.diff(leftComparator, rightComparator);
System.out.println(finalResult.toString());
System.out.println(finalResult.toString());
}