Это похоже на то, что вы хотите:
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;
}
}