title: XML Parser gets stuck on special characters, despite encoding
body: <p>This is the situation as it is:</p>
  
  <p>I'm receiving data from an XML API. This data sometimes contains a special apostrophe character, which causes my parser to crash. This crash only occurs when I read the data from a local file. When I read the data from the stream there is no crash, but I don't get a DOM tree either: it exits without notifying me.</p>
  
  <p>Below you will find a list of attempts we've made to make things work:</p>
  
  <pre><code>// Does not work
  var web = new WebClient();
  web.Encoding = Encoding.UTF8;
  var response = web.DownloadString("http://thetvdb.com/api/apikey/series/" + show.TVDBID + "/");
  var tree = XDocument.Parse(response);
  
  // Works
  var doc = new XmlDocument();
  doc.Load("C:\\Test\\test.xml");
  var response = doc.InnerXml;
  var tree = XDocument.Parse(response);
  
  // Works
  var xmlDoc = XDocument.Parse(File.ReadAllText("c:\\Test\\test.xml", System.Text.Encoding.UTF8));
  var xmlDoc = XDocument.Load("C:\\Test\\test.xml");
  var tree = xmlDoc;
  
  // Does not work
  var web = new WebClient();
  web.Encoding = Encoding.UTF8;
  web.DownloadFile("http://thetvdb.com/api/apikey/series/" + show.TVDBID + "/", "C:\\test.xml");
  var tree = XDocument.Load("C:\\test.xml");
  
  // Does not work
  var web = new WebClient();
  web.Encoding = Encoding.UTF8;
  var data = web.DownloadData("http://thetvdb.com/api/apikey/series/" + show.TVDBID + "/");
  var response = Encoding.UTF8.GetString(data);
  var tree = XDocument.Parse(response);
  </code></pre>
  
  <p>I determine whether or not something works depending on if it reaches the breakpoint in the first line of this loop:</p>
  
  <pre><code>if (root != null) { 
       var lastupdate = root.Element("Series").Element("lastupdated").Value;
  
       foreach (var epi in tree.Descendants("Episode")) {
            var season = epi.Element("SeasonNumber").Value; // Breakpoint here
       }
  }
  </code></pre>
  
  <p>The crashes happen when the parser encounters this apostrophe:
  <img src="https://i.stack.imgur.com/zrRp6.png" alt="enter image description here"></p>
  
  <p>When I replace this character with my own manually entered apostrophe or with <code>&amp;#39</code>, there is no more error thrown and it continues untill the next one.
  When I view the source page of the API request in firefox and chrome, it tells me the encoding is UTF-8 and code examples on the API wiki also show UTF-8 in the header.</p>
  
  <p>This is where I am so far. Any ideas? </p>
  
  <p>I just noticed that my result string from the API query only contains a <code>&lt;Series&gt;&lt;/Series&gt;</code> tag according to the XML/Text/HTML visualizer during debugging, and no <code>&lt;Episode&gt;&lt;/Episode&gt;</code> ones. However, when I execute the same query in my browser it shows me both. Is this possible? When I look at it trough Postman, it shows the episodes.</p>
  
  <p>Update:</p>
  
  <p>When I use Unicode as encoding, I don't receive any warnings and I'm able to completely parse the local xml file! I'm not an encoding expert, are there any downsides to using Unicode? </p>
  
  <p>When using unicode for the stream of data, I get a bunch of asian characters.</p>