2015-11-04 45 views
0

在我的xml文檔中,存在doctype。在使用Apache Axiom解析xml文檔時,它會引發以下錯誤消息:「org.apache.axiom.om.OMException:無法創建OMDocType,因爲XMLStreamReader不支持DTDReader擴展名」。如何忽略Apache的AXIOM中的DTD解析

XMLStreamReader parser = null; 
    try { 
    StAXParserConfiguration standalone = StAXParserConfiguration.STANDALONE; 
    parser= StAXUtils.createXMLStreamReader(standalone, in); 
    // parser = XMLInputFactory.newInstance().createXMLStreamReader(in); 
    } 
    catch (XMLStreamException e) { 
    // TODO Auto-generated catch block 
    e.printStackTrace(); 
    } 
    catch (FactoryConfigurationError e) { 
    // TODO Auto-generated catch block 
    e.printStackTrace(); 
    } 
    StAXOMBuilder builder=new StAXOMBuilder(parser); 
    OMElement rootOMElement = builder.getDocumentElement(); 
+0

從文檔中刪除文檔類型將解決此問題。但是我想要Axiom解析器來照顧這個。 – Vel

回答

1

這將在Axiom 1.2.16中修復(見AXIOM-475)。與此同時,您可以通過使用Woodstox(4.0或更高版本)作爲StAX實現來解決此問題。

+0

謝謝安德烈亞斯:-) – Vel

+0

嗨安德烈亞斯,看來你已經解決了這個問題。你能否提供一個示例代碼? – Vel

+0

示例代碼是什麼? –