This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes DOCTYPE definition Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "DOCTYPE definition" Watch "DOCTYPE definition" New topic

DOCTYPE definition

Karthick Sundaram

Joined: Feb 04, 2007
Posts: 15


I'm a beginner with XML and need some basic help.

This is the general external reference to a DTD.

<!DOCTYPE root-element SYSTEM "filename">

And this is a specific example.

<!DOCTYPE note SYSTEM "Note.dtd">

Where should the Note.dtd file be placed, so that the xml document is validated against this dtd?


SCJP 1.4, SCWCD for J2EE 1.4
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

The parser will treat "Note.dtd" as a path that is relative to the base URL of the XML document it is parsing.

So, usually this means you put the DTD in the same directory as the XML document. If the base URL is an http:// URL then you have to make sure the server will serve the DTD from the appropriate path.

And you have to make sure the parser actually has a base URL for the XML document. If you pass it an InputStream, for example, then it doesn't have one and thus it won't be able to find the DTD.

If you provide the parser with an EntityResolver which locates the DTD itself, then you can put the DTD anywhere you like, as long as the EntityResolver knows where you put it.
I agree. Here's the link:
subject: DOCTYPE definition
It's not a secret anymore!