Another option is com.sun.xml.dtdparser.DTDParser
which is used in the JAXB schema compiler. It has a nice-looking com.sun.xml.dtdparser.DTDParser.parse(InputSource)
method. I could not find any examples for that, but the usage is probably:
// Gets the DTD events
DTDEventListener listener = ...;
// Instantiate the parser
DTDParser parser = new DTDParser();
// Set the nandler
parser.setDtdHandler(reader);
// Parse your DTD source
parser. parse(...);
However I'd first try Xerces (see the other answer) as this DTD parser seems to be quite old. I think this was even me who mavenized it ages ago.
Generally, the task fo generation a sample XML file based on a DTD or XML Schema is not easy, as far as remember, this was a PhD-level resarch topic around 2000. I could not find a link but there was a very nice research paper from IBM if I am not mistaken.
Nowadays, I'd not take DTD but rather XML Schema as basis.