为什么XmlDocument.LoadXml抛出System.Net.WebException?抛出、LoadXml、XmlDocument、WebException

2023-09-04 02:37:35 作者:梦里花落知多少

为什么 System.Xml.XmlDocument.LoadXml 法掷 System.Net.WebException

这真的是让人难以置信的疯狂,如果 MSDN 是正确的, loadXML的应该顶多给我一个 System.Xml.XmlException

不过,我有奇怪的例外,如:

  

基础连接已关闭:连接被意外关闭

 昏暗的文件作为新的XmlDocument
document.LoadXml(< D​​OCTYPE HTML PUBLIC! -  // W3C // DTD XHTML 1.0过渡// ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional。 DTD>&其中X  -  GT;&所述; / X>中)
MSGBOX(document.LastChild.Name)
 

这到底是怎么造成的例外呢?

解决方案

埃德温给你的解决方案,我现在给你的连接中断的原因:

在网上下载ppt文件,下载完成后变成xml document类型怎打开啊

http://www.w3.org/blog/systeam / 2008/02/08 / w3c_s_excessive_dtd_traffic /

Why does System.Xml.XmlDocument.LoadXml method throw System.Net.WebException ?

This is really mind boggling crazy, if MSDN was right, LoadXml should at most give me a System.Xml.XmlException.

Yet I have weird exceptions like:

The underlying connection was closed: The connection was closed unexpectedly.

Dim document As New XmlDocument
document.LoadXml("<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Transitional//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd""><x></x>")
MsgBox(document.LastChild.Name)

What on earth is causing the exception ?

解决方案

Edwin gave you the solution, and I'm giving you the reason for the connection drop:

http://www.w3.org/blog/systeam/2008/02/08/w3c_s_excessive_dtd_traffic/