I don't know of any way to have it automatically picked. I did some thing similar to this, but I had to explicitly specify the directory. Normally, DTDs are kept in /WEB-INF itself. But that is with taglibs and whatnot. They know exactly where to look fot the DTDs. I think you will have to specify it.
You might think about putting it in a public, web accessable, place. Like in /dtd/my.dtd so that you can access it with a URL. That would be an easy way to do it. Most of the validators would swollow that with no problem.
Also, you can specify the DTD's location as a relative path to the current xml document.
or another directory...
or web based...
If you are dynamically generating XML, you might want to use the web-based approach. You will have a consistant URL to work with that will be easier to use than the file system.
If the XML is on the file system in a specific location you could put your DTDs in a directory structure like this:
Then you could specify the DTD like this in your XML DOCTYPE:
I think that you will find it easiest and most flexible to have the DTD web accessable and public. The only reason I would not go with the web-based approach is if I had a security constraint that limited the publicity of the DTD.
I hope this helps...
The squeaky wheel gets the grease. Well, that or replaced...
Joined: Feb 13, 2003
Unfortunately I don't have any control over the XML document itself, its coming from another system, so I cant alter the doctype.
At the moment I've put the DTDs with the XML docs and that seems to work. Unfortunately, I'm not sure this will be an option in the production environment since (again) I have no control over this directory.
Joined: May 26, 2005
We usually turn off validation in production anyway. It is too resource intensive. So throughout development and test it is on. This is to be sure that everyithing is good. Then turn it off and go to production.
This might be a solution for your situation where you do not have control over the xml.
Of course if you cannot trust that the originating XML builder is consistant and valid, you may need to try and find another solition that will work.
Most of the validation I have done is with XMLSchema, not DTD. I know that with XMLSchemas you can specify the schema at runtime. So, maybe this is what you are looking for. Here is an example of validating with xerces an XML file that does not have any namespaces in it:
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com