Prevent DTD download when parsing XML, redux
- by harpo
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?