XmlDocument and slow schema processing

I have an xml template document that I need to load into an XmlDocument. eg,

myXMLDocument.Load(myXMLFile);

However, this is very slow since it loads into dtd. I tried both a "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"local copy of dtd. Both take more or less the same time. If I return to loading dtd by setting this converter to null (for example), I get errors such as "Reference to undeclared entity 'nbsp'"if the document contains this data.

I need to use XmlDocument, as I need to manipulate the DOM before issuing the document. How can I get around these problems?

+5
source share
5 answers

DTD, :

private class DummyResolver : XmlResolver
{
   public override System.Net.ICredentials Credentials
   {
    set
    {
     // Do nothing.
    }
   }

public override object GetEntity(Uri absoluteUri, string role, Type ofObjectToReturn)
   {
    return new System.IO.MemoryStream();
   }
}
+2

ChrisW , - : http://msdn.microsoft.com/en-us/library/bb669135.aspx

11,5 160 , , , . , ChrisW.:)

+3

DTD , - .mod, , . , , "" .

0

, . , :

  • *.mod *.ent, DTD ( XmlResolver URI, )
  • XmlResolver, GetEntity() ,
0

-, null dtd load? - :

class DummyResolver : XmlUrlResolver 
{
    public override Uri ResolveUri (Uri baseUri, String relativeUri) 
    {
       return null;
    }
}

XmlDocument xmlDocument = new XmlDocument();
xmlDocument.XmlResolver = new DummyResolver();

xmlDocument.Load(@"whatever.xml");
-1

All Articles