title: XML Exception: Invalid Character(s)
body: <p>I am working on a small project that is receiving XML data in string form from a long running application. I am trying to load this string data into an <code>XDocument</code> (<code>System.Xml.Linq.XDocument</code>), and then from there do some XML Magic and create an xlsx file for a report on the data.</p>
  
  <p>On occasion, I receive the data that has invalid XML characters, and when trying to parse the string into an <code>XDocument</code>, I get this error.</p>
  
  <blockquote>
    <p>[System.Xml.XmlException]
    Message: '?', hexadecimal value 0x1C, is an invalid character.</p>
  </blockquote>
  
  <p>Since I have no control over the remote application, you could expect ANY kind of character.</p>
  
  <p>I am well aware that XML has a way where you can put characters in it such as <code>&amp;#x1C</code> or something like that.</p>
  
  <p>If at all possible I would SERIOUSLY like to keep ALL the data. If not, than let it be.</p>
  
  <hr>
  
  <p>I have thought about editing the response string programatically, then going back and trying to re-parse should an exception be thrown, but I have tried a few methods and none of them seem successful.</p>
  
  <p>Thank you for your thought.</p>
  
  <p>Code is something along the line of this: </p>
  
  <pre><code>TextReader  tr;
  XDocument  doc;
  
  string           response; //XML string received from server. 
  ... 
  tr = new StringReader (response);   
  
  try
  {
      doc = XDocument.Load(tr);
  }
  catch (XmlException e)
  {
      //handle here?
  }
  </code></pre>