how to remove/delete the DOCTYPE declaration from the XML Document using DOM Parser or SAX Parser in JAVA?
If something you wanted to know is missing. Just mention it in your comments.
thanks
This seems to do 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;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With