unable to find DTD

M

Mithil

Hi ,

I have defined the location of the DTD in the XML file using this tag:

<!DOCTYPE blah SYSTEM "filename.dtd">

I am assuming that the the filename.dtd will be looked up where the
XML file's location (as i give the location of the xml file) is when
being parsed by the parser, in my case a DOM parser. But that doesn't
happen it looks at another default location can anyone please suggest
a fix for this or even explanation of why it happens would be great.

Thanks all,
Mithil
 
J

Joseph Kesselman

Mithil said:
I am assuming that the the filename.dtd will be looked up where the
XML file's location

How have you told the parser where to get the XML file? If you passed
the parser a stream, it probably doesn't know the original document's
URI unless you have explicitly set that.

It's hard to diagnose this without seeing the actual code.
 
M

Mithil

HI Joseph,

I am telling the parser to get the location of the xml file, I don't
stream it to the parser I give the exact location.

i do agree its hard to diagnose this. I think it might be the tomcat
and i was told its k to specify the full path of the DTD in the xml
file if i do that no error props up so its good.

Thanks for your help Joseph
 
J

Joe Kesselman

Mithil said:
I am telling the parser to get the location of the xml file, I don't
stream it to the parser I give the exact location.

Using what parser, configured with what URI Resolver/Entity Resolver,....
i was told its k to specify the full path of the DTD in the xml

Yep. Preferable, in fact; a document doesn't want to change its meaning
just because you've moved it to a new place.
 
M

Mithil

Hi joseph,

I actually find out my error I had a FileInputStream instead of just
File to pass the file to the parser. But my question was why should
that make a difference in locating the DTD file, and sorry for beinlg
hasty. and yeah i m using a DOM parser

Mithil
 
R

Richard Tobin

I actually find out my error I had a FileInputStream instead of just
File to pass the file to the parser. But my question was why should
that make a difference in locating the DTD file

When you specify "filename.dtd" as the location of the DTD, it's
interpreted as a URL. It's a relative URL, so it's interpreted
relative to the location of the containing document, just like '<a
href="page.html">' in a web page. So it tries to look for the DTD in
the same directory as the document. *But* because you gave it a
stream rather than a file, it doesn't know what directory the document
is in, so it's likely to get it wrong.

Analogy: you tell someone that Mr. Smith lives at no. 63. If they're
standing at your front door, this will make sense - it's no. 63 on the
same street. But if you phoned them up, it won't help them.

-- Richard
 
J

Joe Kesselman

Richard said:
the same directory as the document. *But* because you gave it a
stream rather than a file, it doesn't know what directory the document
is in, so it's likely to get it wrong.

Exactly. That's why one of my first questions was whether you were
handing the parser a stream or a URI. If you pass it a stream, most
parsers will let you specify which URI that stream corresponds to so
relative URIs will work -- but you do have to specify that explicitly,
or it's going to either have to guess or not try at all.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,197
Latest member
ScottChare

Latest Threads

Top