• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Where to put DTDs?

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Tony Walters
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:

 
"Don't believe every tiny ad you see on the internet. But this one is rock solid." - George Washington
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic