This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes What if DTDs cannot be accessed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "What if DTDs cannot be accessed" Watch "What if DTDs cannot be accessed" New topic

What if DTDs cannot be accessed

Pankaj Tandon

Joined: Mar 13, 2001
Posts: 4
My question relates to DTDs.
The two ways one can specify DTDs are either using the SYSTEM keyword in the <!DOCTYPE ...> element or the PUBLIC keyword.
If a certain XML doc is sent from host A to host B and it has a DOCTYPE with PUBLIC keyword which references a URL like so:
"-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
How is host B supposed to check the validity of this XML doc. Does it actually go out to the sun site to get the DTD. What if the sun site is down? Also, can I place DTDs on my own servers?
Mark Savory
Ranch Hand

Joined: Feb 08, 2001
Posts: 122
Yes, Host B goes to the sun site to get the DTD. Yes, if the Sun site is down, then the document can not be validated. Yes, you can put the DTD on any server on the network(it can be accessed from a webserver or the file system). The advantage of this particular DTD being on the Sun site is that there's one central document definition for this particular document type. If you have the same DTD on different servers, you have to make sure that they're synchronized.
Pankaj Tandon

Joined: Mar 13, 2001
Posts: 4
Thanks for the reply. But that raises another question. I have used DTDs that are declared with DOCTYPE...PUBLIC in XML docs taht are passed between machines on an intranet setup. No access to the sun site. Yet I do not get a validation error. This was if I wanted to start a webapp using weblogic, say. The web.xml file that describes the webapp, has a PUBLIC DTD declaration. So the question is, how is the validation turned off in weblogic. I don't see an explicit switch/property to do this. Could it be that the turning off of the validation (or making it optional) a part of the XML doc itself?
Marius Holm
Ranch Hand

Joined: Sep 11, 2000
Posts: 84
Hi there!
The point here is that the app in question either validates the XML according to the DTD or it does not. Or, put in another way, either it needs to, or it needs not.
As long as your app is not required to validate the doc, you don't need access to the DTD, the DOCTYPE tag is just ignored.
You should use DTD validation if you expect your app to receive input from external users, whose XML you will not be able to verify before input.
You can not turn off validation in an XML doc. I don't know what 'weblogic' is, but probably (considered today's connectivity conditions around) it will not go to the web to check the DTD for a configuration file (if that's what 'web.xml' is).
The point is that as long as you, as system administrator, are able to keep the config files proper, it would be a serious flaw in any system to let you have downtime because it cannot access a public DTD.
This may change in the future, when connectivity is more or less assured everywhere.
Good luck with your project!
Mark Savory
Ranch Hand

Joined: Feb 08, 2001
Posts: 122
Which XML parser are you using? The parser that I'm using takes a boolean indicating whether the document is to be validated or not.
subject: What if DTDs cannot be accessed
Similar Threads
Calling a servlet on startup
one xml file with more than one dtd file
Need the techinical help for running sample struts program using Myeclipse5.1.1
ejb-jar.xml doctype reference for local DTD reference
weblogic problem