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