Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Servlets and the fly likes Where to put DTDs? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Where to put DTDs?" Watch "Where to put DTDs?" New topic
Author

Where to put DTDs?

Tony Walters
Ranch Hand

Joined: Feb 13, 2003
Posts: 54
Hi All

I'm doing some XML processing in a servlet. Problem is it can't seem to find the (SYSTEM) DTD. Where in the WEB-INF should it go to be automatically picked?

Thanks in advance.
Tony
Rusty Enisin
Ranch Hand

Joined: May 26, 2005
Posts: 107
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...
Tony Walters
Ranch Hand

Joined: Feb 13, 2003
Posts: 54
Thanks Scott

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.
Rusty Enisin
Ranch Hand

Joined: May 26, 2005
Posts: 107
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:

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Where to put DTDs?
 
Similar Threads
wait() method in Thread
Java J2EE/J2ME Contractors
Jokes
Very frustrated in locating a CT java job
quetions to HR regarding the original pay slip modification