XML Element and Attribute Name Verification when Creating New Nodes
The XML Document Object Model (DOM) checks the validity of the names when creating new element nodes or attribute nodes. If the names contain illegal characters, an exception is thrown. To ensure that names are valid and encoded correctly, you need to use the XmlConvert class to encode the name and decode it back at an application level. For more information, see Character Encoding of XML Names and Conversion of XML Data Types. The XmlWriter has methods that do additional work to ensure well-formed XML is generated. For more information, see Well-Formed XML Creation with the XmlTextWriter.