Daniel Burrell wrote:
Hi,
In the following code I attempt to parse an xml file which contains a
DOCTYPE definition.
parser->setValidationScheme(XercesDOMParser::Val_Never);
parser->parse(gXmlFile);
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE collection SYSTEM "C:\this file mya or may not exist and xerces
should not check.dtd">
<collection>
...
</collection>
the schema mentioned in this definition may or may not be available at the
time of parsing.
That's a DTD, not a schema.
For this reason I want xerces to ignore the file mentioned and to continue
parsing without validation.
However using:
parser->setValidationScheme(XercesDOMParser::Val_Never);
Only seems to turn off validation, it does not stop xerces from checking
that the schema referenced is a legitimate one.
and so every time i try to parse an xml file with a dtd that does not exist
yet i get the following error:
Fatal Error at file "C:\valid.xml", line 2, column 41
Message: An exception occurred! Type:RuntimeException, Message:Could not
open DTD file 'C:\dd.dtd'
Yes, the parser will still attempt to load the DTD even when not
validating, since it may define entities and default attributes, etc.
Is there any way to stop xerces performing this check and ignore the missing
dtd compleatly?
The easiest way to handle this situation is to install an EntityResolver
and have it return an empty entity when the parser requests the system
ID of the DTD. For example, you can create a new MemBufInputSource that
points to an empty string.
Dave