在 DaisyDiff 中获取空指针异常 net.sf.saxon.event.ReceivingContentHandler.startElement [英] Getting NULL pointer exception net.sf.saxon.event.ReceivingContentHandler.startElement in DaisyDiff

查看:68
本文介绍了在 DaisyDiff 中获取空指针异常 net.sf.saxon.event.ReceivingContentHandler.startElement的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 DaizyDIff 库来比较两个 html 文件.我写了一个 java 代码来实现 DaizyDiff.但是在运行时,我在 net.sf.saxon.event.ReceivingContentHandler.startElement 上遇到了 NULL 指针异常

I'm using DaizyDIff library to compare two html files. I wrote a java code to implement the DaizyDiff. but while running I'm getting NULL pointer exception on net.sf.saxon.event.ReceivingContentHandler.startElement

我在 SAXTransformerFactory 上尝试了多种方法,但我想不通

I have tries multiple approach on SAXTransformerFactory , but I couldn't figure out

public static void daisyDiffTest() throws Exception {
    String html1 = "<html><body>var v2</body></html>";
    String html2 = "<html>  \n  <body>  \n  Hello world  \n  </body>  \n  </html>";

    try {
        StringWriter finalResult = new StringWriter();
        SAXTransformerFactory tf = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
        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));

        ContentHandler postProcess = result;
        Locale val = Locale.ENGLISH;
        DaisyDiff.diffHTML(new InputSource(new StringReader(html1)), new InputSource(new StringReader(html2)),
                postProcess, "test", val);
        System.out.println(finalResult.toString());
    } catch (SAXException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

HTML 文件中的预期结果会有所不同.

Expected result would be diff in the HTML file.

推荐答案

如果不知道 DaisyDiff 是什么,或者它叫什么名字,就很难知道.很有可能它没有经过测试或支持与 Saxon 一起使用.

It's hard to know without knowing what DaisyDiff is, or what calls it makes. It's quite possible that it's not tested or supported for use with Saxon.

在 SAX ContentHandler 中传递给 startElement() 事件的数据格式取决于 XML 解析器的配置选项,而当 Saxon 作为 ContentHandler 以这种方式调用时的问题是它无法发现什么解析器使用的配置选项.

The format of data passed to the startElement() event in a SAX ContentHandler depends on the configuration options of the XML parser, and the problem when Saxon is invoked as a ContentHandler in this way is that it has no way of discovering what configuration options the parser is using.

如此处的 Javadoc 文档所述:http://www.saxonica.com/documentation/index.html#!javadoc/net.sf.saxon.event/ReceivingContentHandler@startElement 如果解析器发出的事件不对应适当配置的解析器会发出什么,ReceivingContentHandler 将以不可预测的方式失败.

As stated in the Javadoc documentation here: http://www.saxonica.com/documentation/index.html#!javadoc/net.sf.saxon.event/ReceivingContentHandler@startElement if the events emitted by the parser don't correspond to what an appropriately configured parser would emit, the ReceivingContentHandler will fail in unpredictable ways.

发布异常的堆栈跟踪可能很有用.

Posting the stack trace of the exception might be useful.

这篇关于在 DaisyDiff 中获取空指针异常 net.sf.saxon.event.ReceivingContentHandler.startElement的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆