Search code examples
xmlaxiom

How to ignore DTD parsing in Apache's AXIOM


In my xml document , doctype is present. While parsing the xml document using Apache Axiom , it throws an following error msg "org.apache.axiom.om.OMException: Cannot create OMDocType because the XMLStreamReader doesn't support the DTDReader extension".

   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();

Solution

  • This will be fixed in Axiom 1.2.16 (see AXIOM-475). In the meantime you can work around this issue by using Woodstox (4.0 or above) as StAX implementation.