2009-12-03 51 views
0

我想解析使用DOM解析器的XML文檔。我在執行doc = builder.parse(xmlDataFile)時得到了空指針異常。XML中的外部實體在DocumentBuilder.parse(「file」)中導致空指針異常;

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行編號指向 - >文檔= builder.parse( xmlDataFile);

+0

一些示例代碼和需要堆棧跟蹤中的Xerces的錯誤。 – skaffman 2009-12-03 08:54:47

回答

0

Solution。但是錯誤的原因真的是未知的,因爲解決方案從未說明出了什麼問題。 :(