0

I have a problem reading an html file using XmlDocument. Project is C# Windows Forms, VS2012

{"Error en el servidor remoto: (500) Error interno del servidor."}
Error in remote server: (500) Server Internal Error Error

I save a page to html

I can reopen the page in the browser OK.
I also can read it using File.ReadAllText so isn't security.

I try loading a test.html <html><b>HELLO WORLD</b></html> and load ok.

So my guess is something in the Save As from the browser damage the file?

Is there a way of make a partial load or check what part is causing the error?

string curFile = @"C:\Uti\CambiaImagen.html";
if (File.Exists(curFile)) {
    string html = File.ReadAllText(curFile);

    //XmlDocument xd = new XmlDocument();
    //xd.Load(curFile);
}
Juan Carlos Oropeza
  • 47,252
  • 12
  • 78
  • 118
  • 1
    Error text you've shown has nothing to do with XmlDocument, it is just response with errorcode from webserver. Try to elaborate more and add more details to your question. Also noitce - basically you can't parse any html using XmlDocument since very often html is not "well-formed" in terms of xml. – Andrey Korneyev Jun 18 '15 at 15:23
  • @AndyKorneyev I include a pic of the error, I know there isn't a webserver because I'm reading a file in a desktop app. But that is the error I'm Getting. – Juan Carlos Oropeza Jun 18 '15 at 15:27
  • 1
    @JuanCarlosOropeza from your screenshot it can be clearly seen that exception was raised by `HttpWebRequest.GetResponse`, so it is server-side exception and it has nothing to do with XmlDocument. – Andrey Korneyev Jun 18 '15 at 15:32
  • You need to show us the XML you're loading, then. It's possible `XmlDocument` is trying to load some external resource (DTD or something). Though, as has been said, don't use `XmlDocument` to load HTML - it likely won't work. – Charles Mager Jun 18 '15 at 15:38
  • @AndyKorneyev Then why I get that exeception on xd.Load(curfile) ? – Juan Carlos Oropeza Jun 18 '15 at 15:38
  • @CharlesMager Is a 54kb file how I show that here? Im checking the HtmlAgilePack, But doesnt have much documentation – Juan Carlos Oropeza Jun 18 '15 at 15:41
  • 1
    @AndyKorneyev you can get a `WebException` if it fails to load the DTD - see [this question](http://stackoverflow.com/questions/7388949/why-does-xmldocument-loadxml-throw-system-net-webexception), for example. – Charles Mager Jun 18 '15 at 15:43
  • @CharlesMager As your suggestion Setting XmlResolver = null solve the WebExecption error. But now I have a sintaxis error. So how i share the big html here? – Juan Carlos Oropeza Jun 18 '15 at 15:54
  • I don't think there's any point - HTML isn't XML, `XmlDocument` is the wrong tool for the job. Giving us the HTML won't change that. – Charles Mager Jun 18 '15 at 15:55

0 Answers0