title: How can I reset XmlTextWriter.WriteValue after it fails to write
body: <p>In certain conditions that I cannot predict the following expression that uses a XmlTextWriter</p>
  <p><code>writer.WriteValue(value)</code></p>
  <p>throws an <code>ArgumentException</code> because the data does contain invalid XML characters.</p>
  <p>When the Exception is thrown I can fix the XML by sanitizing the string like this</p>
  <pre><code>var validXmlChars = text.Where(XmlConvert.IsXmlChar).ToArray();
  return new string(validXmlChars);
  </code></pre>
  <p>The problem is that when I try to do that and perform the write operation again, I get an InvalidOperationException that says that</p>
  <p><em>The Content token in Error state will cause the XML to be invalid</em></p>
  <p>Is there a way to reset the XmlTextWriter and write the value again with WriteValue so I can write the proper string after an exception has occurred?</p>
  <p>Thank you.</p>