How to remove / delete a DOCTYPE declaration from an XML document?

How to remove / delete a DOCTYPE declaration from an XML document using DOM Parser or SAX Parser in JAVA?

If something you wanted to know is missing. Just mention this in your comments.

thanks

+4
source share
1 answer

This is similar to what you want:

try { XMLInputFactory inFactory = XMLInputFactory.newFactory(); XMLOutputFactory outFactory = XMLOutputFactory.newFactory(); XMLEventReader input = inFactory.createXMLEventReader( new FileInputStream("test.xml")); XMLEventReader filtered = inFactory.createFilteredReader( input, new DTDFilter()); XMLEventWriter output = outFactory.createXMLEventWriter( System.out); output.add(filtered); output.flush(); } catch (XMLStreamException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } static class DTDFilter implements EventFilter { @Override public boolean accept(XMLEvent event) { return event.getEventType() != XMLStreamConstants.DTD; } } 
+5
source

All Articles