title: Why .NET XML API doesn't protect me from null character?
body: <p>My application receive strings from outside and construct an XML document</p>
  
  <pre><code>string fromOutside = "\0";
  XAttribute a = new XAttribute(fromOutside);
  </code></pre>
  
  <p>when the attribute value contains null character then I got exception when trying to save XML to the disk (when it goes into <code>XmlWriter</code>)</p>
  
  <pre><code>System.ArgumentException : '.', hexadecimal value 0x00, is an invalid character.
  </code></pre>
  
  <p>Even the <code>SecurityElement</code> class doesn't help</p>
  
  <pre><code>Assert.IsFalse(SecurityElement.IsValidAttributeValue("\0"));
  </code></pre>
  
  <p>What is the best way to construct the XML document from strings which may contain such invalid characters like null character etc?</p>