tags:

views:

127

answers:

2

A C# program of ours reads an XML file. The XML file has standalone='no' header.

The DOCTYPE used to look like:

<!DOCTYPE foo SYSTEM "silly.dtd">

where silly.dtd is not sitting right there next to the file.

For various reasons, I changed this to

<!DOCTYPE foo PUBLIC "-//Some Public Id" "urn:outerspace:silly.dtd">

I expected nothing to change, since the DTD could not be opened as './silly.dtd' before, and it can't be opened at 'urn:outerspace:silly.dtd' now. The only difference was that a catalog resolver wouldn't have to worry about the absolutization of the system ID.

Imagine my surprise to get an exception from the .NET runtime, apparently trying to open the DTD at the urn: address.

Can some kind person direct me to a recipe to tell .NET to just quietly give up in this case? I know how to do this in Java, but in .NET I'm a bit lost.

+1  A: 

Implement your own XmlResolver to handle this (you could just inherit from XmlUrlResolver), then plug it into a XmlTextReader and pass the reader to the XmlDocument.

Mauricio Scheffer
A: 

The reader will not attempt to access the dtd if you have the following properties: .ProhibitDtd=false; .XmlResolver=null;

bill seacham
That's not what happened to me. When I set the resolver to null in the reader options it went and created a default resolver.
bmargulies