title: Unescaping XML entities using XmlReader in .NET?
body: <p>I'm trying to unescape XML entities in a string in .NET (C#), but I don't seem to get it to work correctly.</p>
  
  <p>For example, if I have the string <code>AT&amp;amp;T</code>, it should be translated to <code>AT&amp;T</code>.</p>
  
  <p>One way is to use HttpUtility.HtmlDecode(), but that's for HTML. </p>
  
  <p>So I have two questions about this:</p>
  
  <ol>
  <li><p>Is it safe to use HttpUtility.HtmlDecode() for decoding XML entities?</p></li>
  <li><p>How do I use XmlReader (or something similar) to do this? I have tried the following, but that always returns an empty string:</p>
  
  <pre><code>static string ReplaceEscapes(string text)
  {
      StringReader reader = new StringReader(text);
  
      XmlReaderSettings settings = new XmlReaderSettings();
  
      settings.ConformanceLevel = ConformanceLevel.Fragment;
  
      using (XmlReader xmlReader = XmlReader.Create(reader, settings))
      {
          return xmlReader.ReadString();
      }
  }
  </code></pre></li>
  </ol>