System.Xml.XmlDocument,缓存外部依赖项DTD的最佳方法是什么? [英] System.Xml.XmlDocument, what's the best way to cache an external dependency DTD?

查看:158
本文介绍了System.Xml.XmlDocument,缓存外部依赖项DTD的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将有效的XHTML加载到XmlDocument中,但是加载需要2秒钟。我发现,如果放下DTD,它是即时的,但随后我必须替换& nbsp;到 等。已声明的HTML实体数量很多,因此我觉得应该加载DTD。那么,以最少的人工来预加载DTD的最简单方法是什么?也许我可以说是将DTD作为资源文件放入程序集中并注入..?有建议吗?

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?

推荐答案

我在这里找到了一种技术,方法是实现抽象类XmlResolver并将其设置为XmlDocument的XmlResolver属性。抽象类实现返回所请求URL的MemoryStream对象,该对象包含DTD或通常通过HTTP加载的其他任何资源。

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

这篇关于System.Xml.XmlDocument,缓存外部依赖项DTD的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆