Making Xerces ignore a DTD
I’m just trying to write a SAX parser for the XML log files generated from the Logging API if you use the XMLFormatter.
There are a couple of problems with the XML generated. One is that the XML is not well formed until the log file is “completed” because it doesn’t have a final </log> element (not surprising really).
The second is that it declares a DTD as follows:
Now it’s fairly easy to find out what the DTD should be, it’s in the JavaDoc and a quick search on Google reveals it. But I can’t guarantee it’ll be in the right place so that I can just load it.
No problem, I thought, I’ll just turn off validation and then it won’t matter. Wrong! Even with validation switched off, it still tries to load it and I get a FileNotFoundException.
However, by delving in the source code I finally found that if you switch off two features, then it does ignore the external DTD. So add this to your code if you want to ignore DTDs:
If anyone knows a better way then please let me know!