System.Xml.XmlDocument, what's the best way to

2019-07-27 11:11发布

问题:

I'm loading valid XHTML into an XmlDocument, but it takes 2 seconds to load. I've found that if I drop the DTD, it's instant, but then I have to replace   to  , etc. The number of declared HTML entities is large, so I feel the DTD should be loaded. So what is the easiest way to pre-load the DTD with minimal manual labor? Perhaps if I could, say, put the DTD into the assembly as a resource file and inject it in..? Any suggestions?

回答1:

I found a technique here, by implementing the abstract class XmlResolver and setting it to the XmlDocument's XmlResolver property. The abstract class implementation returns a MemoryStream object for the URL being requested, which contains the DTD or whatever other resource would normally be loaded over HTTP.

http://www.codeproject.com/KB/XML/HTML2XHTML.aspx?display=Print