XML中的外部实体在DocumentBuilder.parse(“file”)期间导致空指针异常;

时间:2009-12-03 08:51:14

标签: java xml parsing nullpointerexception

我试图使用DOM Parser解析XML文档。

执行doc = builder.parse(xmlDataFile);

时出现空指针异常

XML数据文件中的实体很少。在删除特定实体时, 我能够成功解析文件

实体有点像这样

<!ENTITY SAMPLE.TIF SYSTEM "SAMPLE.TIF" NDATA TIF>

可能是什么原因?

修改

以下是代码:

        DocumentBuilderFactory aFactory = DocumentBuilderFactory.newInstance();
        aFactory.setValidating(false);
        aFactory.setFeature("http://xml.org/sax/features/namespaces", false);
        aFactory.setFeature("http://apache.org/xml/features/validation/schema", false);
        aFactory.setIgnoringComments(true);
        builder = aFactory.newDocumentBuilder();
        doc = builder.parse(xmlDataFile);

这是追踪:

 at com.sun.org.apache.xerces.internal.dom.DeferredDocumentImpl.setChunkIndex(DeferredDocumentImpl.java:1944)
    at com.sun.org.apache.xerces.internal.dom.DeferredDocumentImpl.appendChild(DeferredDocumentImpl.java:644)
    at com.sun.org.apache.xerces.internal.parsers.AbstractDOMParser.characters(AbstractDOMParser.java:1191)
    at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.characters(XMLDTDValidator.java:862)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:463)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:807)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:107)
    at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:225)
    at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:283)
    at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:180)
    at XMLParser.Parse(XMLParser.java:89)
    at Main.main(Main.java:116)

89行号指向 - &gt; doc = builder.parse(xmlDataFile);

2 个答案:

答案 0 :(得分:0)

Solution。但是错误的原因实际上是未知的,因为解决方案永远不会说明出了什么问题。 :(

答案 1 :(得分:0)

这是Xerces中的一个错误,修复版本为2.9.1

https://issues.apache.org/jira/browse/XERCESJ-977