The WriteChars method of the XmlWriter class writes characters to XML. It takes an array of characters and writes one character at a time.

The following code snippet takes an array of characters and writes them to an XML file.

using (XmlWriter writer = XmlWriter.Create("M.xml"))
{

writer.WriteStartDocument();

char[] ch = new char[6];
ch[0] = 'm';
ch[1] = 'a';
ch[2] = 'h';
ch[3] = 'e';
ch[4] = 's';
ch[5] = 'h';

writer.WriteStartElement("WriteChars");

writer.WriteChars(ch, 0, ch.Length);

writer.WriteEndElement();

writer.WriteEndDocument();

}