Convert "iso-8859-1" to "utf-8" with HTML Agility Pack and xpath

c# html-agility-pack iso-8859-1

Question

I'm trying to get a piece of web page, but I have a problem with special characters. how to convert the data to obtain a correct reading? the website use ISO 8859-1 and i must use UTF 8.

    string url = "http://www.ta-meteo.fr/troyes.htm";
       HtmlWeb web = new HtmlWeb();
       HtmlDocument doc = web.Load(url);
       HtmlNode bulletinMatin = doc.DocumentNode.SelectSingleNode("//*[@id='blockdetday0']/div[1]/p[1]");
       MessageBox.Show(bulletinMatin.InnerText);    

thanks.

Popular Answer

I solved the problem

 string url = "http://www.ta-meteo.fr/troyes.htm";

 Encoding iso = Encoding.GetEncoding("iso-8859-1");
   HtmlWeb web = new HtmlWeb()
        {
            AutoDetectEncoding = false,
            OverrideEncoding = iso,
        };

   HtmlDocument doc = web.Load(url);
   HtmlNode bulletinMatin = doc.DocumentNode.SelectSingleNode("//*[@id='blockdetday0']/div[1]/p[1]");
   MessageBox.Show(bulletinMatin.InnerText);     



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why