Prevent DTD download when parsing XML, redux
Posted
by harpo
on Stack Overflow
See other posts from Stack Overflow
or by harpo
Published on 2010-05-27T17:17:06Z
Indexed on
2010/05/27
17:21 UTC
Read the original article
Hit count: 302
I have a folder full of XHTML files, and a console program to process them.
The problem is, it doesn't work when I'm offline, because
The remote name could not be resolved: 'www.w3.org'
A number of sites, including this one, say to set the XmlResolver
to null
. That is not not working.
I have tried setting the XmlResolver to null every way that I can think of: in the XmlDocument, in XmlTextReader, and in the XmlReaderSettings. I believe that it's just creating a default instance. I have also tried implementing my own XmlResolver, but I don't know what to return for external items.
public class NonXmlResolver : XmlUrlResolver
{
public override object GetEntity( Uri absoluteUri, string role, Type ofObjectToReturn )
{
if ( absoluteUri.Scheme == "http" )
throw new Exception("What you talking 'bout, Willis?");
else
return base.GetEntity( absoluteUri, role, ofObjectToReturn );
}
}
The documents do not use any special entities, only pure XML. This is possible, right?
© Stack Overflow or respective owner