0

Are there any quick methods that don't require external libraries that can fix webresponse encodings back to the original text. (I'm not sure if the encoding is the actual cause or if my terminology is correct here?)

As an example, my code below returns the first line but I need the second line. So doc.InnerXML reads:

<description>S&amp;P500</description> //What I get <description>S&P500</description> //What I want 

I was looking for a generic solution that would fix all instances such as spaces, apostrophes, ampersand etc.

The html agility pack seems a bit overkill for this and was hoping there was a setting on either the response or XML doc?

private List<rss> GetRSS() { List<rss> rssList = new List<rss>(); try { string url = Properties.Settings.Default.RSSFeedURL; string un = Properties.Settings.Default.RSSUN; string pw = Properties.Settings.Default.RSSPW; if (url != "") { // Make Remote Request Uri uri = new Uri(url); HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(url); if (un != "") { wr.Credentials = new NetworkCredential(un, pw); } // Set the HTTP properties wr.Timeout = 10000; // Read the Response WebResponse resp = wr.GetResponse(); Stream stream = resp.GetResponseStream(); // Load XML Document XmlTextReader reader = new XmlTextReader(stream); reader.XmlResolver = null; XmlDocument doc = new XmlDocument(); doc.Load(reader); //Load rssList; } } catch (Exception ex) { //Bubble Exception up to DoWork and then RunWorkComplete throw; } finally { //Cleanup } return rssList; } 
2
  • Excellent! That is exaclty what I need. If you add it as an answer I&#39;ll accept. Thanks! Commented Nov 20, 2013 at 17:50
  • Side note: <description>S&P500</description> is invalid XML as it does not have & encoded... Please don't give invalid XML to others as it always causes "how to read XML with invalid characters" questions... Commented Nov 20, 2013 at 18:15

1 Answer 1

1

I'm not into WinForms usually, but I looked for a similar function to what exists in ASP.NET and found WebUtility.HtmlDecode() which seems to be exactly what you're looking for

Sign up to request clarification or add additional context in comments.

Comments