System.Xml.XmlDocument, what's the best way to cache an external dependency DTD?

匆匆过客 提交于 2019-12-24 10:47:45

问题


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



来源:https://stackoverflow.com/questions/913214/system-xml-xmldocument-whats-the-best-way-to-cache-an-external-dependency-dtd

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!