• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Wep application DTD location reference problem

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a DTD mydefn.dtd to validate an XML file. In XML file I am referencing the dtd as follows

<!DOCTYPE mydefn SYSTEM "dtd/mydefn.dtd">

1) In case of a Java Application, if I place the mydefn.dtd in to "dtd" folder at the root of application. It works fine.

2) In case of a Java Web Application it tries to look for mydefn.dtd in bin directory of Tomcat

.....\jakarta-tomcat-5.5.7\bin\dtd\module-config.dtd

What steps do I need to take in web application to teach it to look into a some specified location under the deployment directory ??

Thanks
 
Marshal
Posts: 26914
82
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The XML recommendation says that when your DTD's location is specified by a relative URL (as yours is), then the parser should interpret that as relative to the document in which the DTD is included. However if the document doesn't have a URL, because you give the parser a FileInputStream or something like that, then presumably the parser falls back on some default, like the current working directory in this case.

In this situation you can write an EntityResolver that finds the DTD yourself, and give that EntityResolver to the parser by calling its setEntityResolver method. The API documentation for EntityResolver has a pretty good example of what to write.
 
Vijay P
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The EntityResolver worked out well

public class MyEntityResolver implements EntityResolver {

public InputSource resolveEntity (String publicId, String systemId) {
// this method gives you an opportunity to create appropriate
// InputSource and return it.
// You could find the DTD file
// Where loader is class loader for your classes
// Enumeration resources = loader.getResources("dtd/mydefn.dtd");
// new InputSource(inputstream);
}
}
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic