Where to put local DTD files in Java projects

I'm working on a Netbeans project where the program funcion is driven by an XML configuration file, which will be distributed with the program.

It's structured enough to warrant a DTD. The problem is, accesing it.

I'm currently accessing the XML as a resource, in the same directory as Main.class, which is in a package directory. Using a system <!DOCTYPE with a simple filename for the DTD works fine in the Netbeans XML editor, but, of course, when I run the program it runs with the project base as the current directory and can't find it. And the situation will be even worse when I prepare the program for distribution.

Anyone found a tidy approach to this? Is there some way of modifying the way the DocumentBuilder accesses DTDs?>

[772 byte] By [malcolmmca] at [2007-10-3 7:45:52]
# 1
You create an EntityResolver that retrieves the DTD, and give it to the parser.Haven't actually done this, and the credit for knowing it goes to Dr Clap.
kdgregorya at 2007-7-15 2:47:16 > top of Java-index,Java Essentials,Java Programming...
# 2

Thanks - that works fine and is quite neat.

builder.setEntityResolver(new EntityResolver() {

public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {

if(systemId.endsWith("lapsync.dtd")) {

return new InputSource(getClass().getResourceAsStream("lapsync.dtd"));

} else

throw new SAXException("Unknown entity " + publicId + " - " +

systemId);

}

});

malcolmmca at 2007-7-15 2:47:16 > top of Java-index,Java Essentials,Java Programming...