You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by "David H. Cook" <dc...@smartlynx.com> on 2000/11/30 22:19:06 UTC
Non-validating parse causes presence of the DTD to be checked?
Xerces developers:
I'm writing some simple XML-parsing code, using the 'Xerces'
parser, and the SAX V2.0 APIs, in the Java language. (I'm using
the O'Reilly textbook "Java and XML", chapters 3 and 5, for
additional guidance.)
And, I've now found what appears to be a bug in Xerces parser,
relating to how it handles the reference to the DTD that can be
present in an XML stream.
(This gets a bit subtle, so bear with me.)
I'm writing a client app, which talks to a server.
That server sends its clients an XML-stream, which happens to contain an
external reference to a DTD. That reference happens to look like:
<!DOCTYPE vdaProject SYSTEM "file:///C:/smartlynx/vda.dtd">
One (supposed) 'solution' would be to change the server to NOT
reference the DTD...i.e. either using an XML-comment tag around it,
or exclude the DTD reference entirely. However, I argue that, in
theory, the client will NOT normally have control over the server.
Also, some other client program may WANT the DTD present, because it
wanted to do a 'DTD-validating' parse! And, certainly, the server
should NOT have to be designed such that a client would have to
tell the server whether or not to insert a DTD-reference in the
XML stream. Rather, as I see it, the client gets to decide
whether to do a validating or a non-validating parse.
(My client parser happens to be running on a Windows-NT platform,
though that fact is NOT related to the issue, as far as I know.)
My client wants to just parse and use the XML stream, WITHOUT
validating against the DTD. So, it contains a line of code which
is supposed to tell the parser NOT to validate. That line reads:
parser.setFeature("http://xml.org/sax/features/validation", false);
I'm unsure whether this line of code is 'partially' working or
is not working at all. I run two test cases. In one case,
I place an actual copy of the DTD on my client machine at:
C:/smartlynx/vda.dtd
In that case, the parse completes, as you might expect. However, in
the other (failing) test case, when I remove the
actual copy of the DTD from the client machine, the parse fails
with:
**Parsing Fatal Error**
(...)
Message: File "file:///C:/smartlynx/working/xml/vda.dtd" not found.
However, I argue that, if validation has actually been set to
disabled, then the Xerces-supplied portion of the parser should
NOT be trying to test for the actual presence of the DTD! (i.e.
that's the bug, as I see it...Xerces should NOT be, but is,
erroneously verifying presence of the DTD for a non-validating
parse. It should do that test if and only if the parse is a
validating parse.) Stated another way, we had no intention of
needing a copy of the DTD on the client machine. (Or, anywhere,
unless we ever had need to do a validating parse. But, right now,
to workaround this present parser idiosyncracy, I am testing
with a DTD present.)
A week or so ago, I asked in newsgroup 'comp.text.xml'
about this issue. It was suggested that I try also adding the line
of code:
parser.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar",
true);
I've tried adding that line (while also leaving the first one in
place). And, I tried that line with args of both 'true' and 'false',
but parsing still stops with the same 'DTD-not-found' symptom.
So, is it a Xerces bug, or is there something else I should
be doing in the client-side coding?
I'm posting this bug report here, because the website says to.
(Website says that the 'bugzilla-database' for Xerces parser issues
has been discontinued due to security issues.)
Thanks for any info.
Regards...
Dave
Re: Non-validating parse causes presence of the DTD to be checked?
Posted by Luke Blanshard <lu...@quiq.com>.
"David H. Cook" wrote:
> And, I've now found what appears to be a bug in Xerces parser,
> relating to how it handles the reference to the DTD that can be
> present in an XML stream.
No, unfortunately the parser MUST read external DTDs, so it can pick up default
attribute values, etc. This is mandated by the spec, even.
This xml page you're getting from your server has not been written to be vended by a
server. It is not reasonable to reference a file in the doctype statement:
> <!DOCTYPE vdaProject SYSTEM "file:///C:/smartlynx/vda.dtd">
This should be something like "http://..." or even just a relative path like
"../smartlynx/vda.dtd".
Luke
RE: Non-validating parse causes presence of the DTD to be checked?
Posted by David Cook <dc...@smartlynx.com>.
David -
Beautiful. I suspected there was a workaround
for this restriction. Thanks for pointing it out!
Right after I read your note, I scouted out this
EntityResolver thing in the O'Reilly book "Java and XML",
and the basic API is also mentioned there (page 432).
So, I'm sure I'll be able to get it working.
Thanks again for the heads-up! I love it that
now we won't have to change our 'already in production'
server code.
Cheers...
Dave
-----Original Message-----
From: David Gommeren [mailto:gommeren@dial.pipex.com]
Sent: Friday, December 01, 2000 05:16 AM
To: xerces-j-dev@xml.apache.org
Subject: Re: Non-validating parse causes presence of the DTD to be
checked?
Hi,
> And, I've now found what appears to be a bug in Xerces parser,
> relating to how it handles the reference to the DTD that can be
> present in an XML stream.
In my ignorance I asked the same question, the reply is:
Install an EntityResolver on the parser which handles loading of all
external documents (including the DTD). It can decide to not load the DTD.
Look at this lists' archives for how and what (I haven't gotten round myself
to apply the changes).
Kind regards,
David Gommeren
--
gommeren@dial.pipex.com
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org
Re: Non-validating parse causes presence of the DTD to be checked?
Posted by David Gommeren <go...@dial.pipex.com>.
Hi,
> And, I've now found what appears to be a bug in Xerces parser,
> relating to how it handles the reference to the DTD that can be
> present in an XML stream.
In my ignorance I asked the same question, the reply is:
Install an EntityResolver on the parser which handles loading of all
external documents (including the DTD). It can decide to not load the DTD.
Look at this lists' archives for how and what (I haven't gotten round myself
to apply the changes).
Kind regards,
David Gommeren
--
gommeren@dial.pipex.com