Hi Steve,
The white spaces you add are there. Your code appends a single space character in front of the value.
If you are missing the indentation, bear in mind that WriteWhiteSpace isonly used when manually formatting the xml, which means effectively overriding the indentation. Furthermore, indentation won't happen on the innermost node, and since you only have a single node it won't be broken on two lines. The code below is probably more what you seek.
writer.WriteStartElement("data");
writer.WriteStartElement("innerdata");
writer.WriteValue(" data with leading space");
writer.WriteEndElement();
writer.WriteEndElement();
On Mon, 19 Feb 2007 18:10:35 +0100, Steve Richter <St************@gmail.comwrote:
when I run the following code the leading spaces of the "data" node
are removed. How do I retain whitespace?
private void CreateBasicXmlDocument()
{
XmlWriterSettings writeSettings = new XmlWriterSettings();
writeSettings.Indent = true;
XmlWriter writer = XmlWriter.Create( filePath, writeSettings );
writer.WriteStartElement("data");
writer.WriteWhitespace(" ");
writer.WriteValue(" data with leading space");
writer.WriteEndElement();
writer.Close();
}
--
Happy coding!
Morten Wennevik [C# MVP]