Verify Xml Chars
using System; using System.Xml; public class Sample { public static void Main() { XmlTextWriter writer3 = new XmlTextWriter("outFile.xml", null); char illegalChar = '\uFFFE'; string charsToVerify = "Test String "; try { writer3.WriteStartElement("root"); writer3.WriteStartElement(XmlConvert.VerifyXmlChars(charsToVerify + illegalChar)); writer3.WriteString("ValueText"); writer3.WriteEndElement(); writer3.WriteEndElement(); writer3.Close(); } catch (XmlException e) { Console.WriteLine(e.Message); writer3.Close(); } } }