Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
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
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "DOCTYPE definition" Watch "DOCTYPE definition" New topic
Author

DOCTYPE definition

Karthick Sundaram
Greenhorn

Joined: Feb 04, 2007
Posts: 9
Hi,

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?

Thanks,
Karthick


SCJP 1.4, SCWCD for J2EE 1.4
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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: http://aspose.com/file-tools
 
subject: DOCTYPE definition