z.mingjie
z.mingjie

Reputation: 31

Why does xmlDocument Load throw timeout error?

I use System.Xml.XmlDocument to load a file,then wait a minute throw the timeout error. Curiously, the code can work in another project.

  1. I try Use System.IO.File.Open this file, it's no problem.
  2. XmlDocument.LoadXml() is throw the error too.

    System.Xml.XmlDocument doc = new XmlDocument();
    doc.Load(@"D:\work\xxx.svg");
    

add:

I see the stacktrace info, it's WebException, error code System.Net.HttpWebRequest.GetResponse().

So the XmlDocument.Load() method is think of my filepath as url, but i don't understand why it work in another project is all right

Upvotes: 1

Views: 637

Answers (1)

z.mingjie
z.mingjie

Reputation: 31

I follow the stacktrace, saw the problem:

[XmlException: Open external DTD "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd": An error occurred while the operation timed out. ]

Then I add XMLreaderSetting:

XmlDocument xmlDoc = new XmlDocument();
XmlReaderSettings settings = new XmlReaderSettings();
settings.DtdProcessing = DtdProcessing.Ignore;
XmlReader reader = XmlReader.Create(@"D:\\111.txt", settings);
xmlDoc.Load(reader);

They final work.

But I am curious why in another project is no problem.

I hope this answer can help another with the same difficulties.

Upvotes: 2

Related Questions