You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xerces.apache.org by Daniel Burrell <da...@gmail.com> on 2008/08/03 16:42:31 UTC

XercesDOMParser::Val_Never still complains about invalid file.

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.
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'

Is there any way to stop xerces performing this check and ignore the missing
dtd compleatly?

Re: XercesDOMParser::Val_Never still complains about invalid file.

Posted by Daniel Burrell <da...@gmail.com>.
That sounds even better, Thanks.

On Mon, Aug 4, 2008 at 7:00 AM, Boris Kolpackov <bo...@codesynthesis.com>wrote:

> Hi David,
>
> David Bertoni <db...@apache.org> writes:
>
> > 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.
>
> I think an even easier way would be to call setLoadExternalDTD(false).
>
> Boris
>
>
> --
> Boris Kolpackov, Code Synthesis Tools
> http://codesynthesis.com/~boris/blog<http://codesynthesis.com/%7Eboris/blog>
> Open source XML data binding for C++:
> http://codesynthesis.com/products/xsd
> Mobile/embedded <http://codesynthesis.com/products/xsdMobile/embedded>validating XML parsing:
> http://codesynthesis.com/products/xsde
>

Re: XercesDOMParser::Val_Never still complains about invalid file.

Posted by Boris Kolpackov <bo...@codesynthesis.com>.
Hi David,

David Bertoni <db...@apache.org> writes:

> 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.

I think an even easier way would be to call setLoadExternalDTD(false).

Boris


-- 
Boris Kolpackov, Code Synthesis Tools   http://codesynthesis.com/~boris/blog
Open source XML data binding for C++:   http://codesynthesis.com/products/xsd
Mobile/embedded validating XML parsing: http://codesynthesis.com/products/xsde

Re: XercesDOMParser::Val_Never still complains about invalid file.

Posted by David Bertoni <db...@apache.org>.
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