Connecting Tech Pros Worldwide Forums | Help | Site Map

retaining leading whitespace in text of an xml node

Steve Richter
Guest
 
Posts: n/a
#1: Feb 19 '07
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();
}


Bjoern Hoehrmann
Guest
 
Posts: n/a
#2: Feb 21 '07

re: retaining leading whitespace in text of an xml node


* Steve Richter wrote in microsoft.public.dotnet.xml:
Quote:
>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();
}
How do you expect the writer to know when your white space is and is not
significant to you? It needs to know because you are asking it to indent
your content, which necessarily implies changes in the amount of white
space. If you turn automatic formatting off, your white space should be
preserved.
--
Björn Höhrmann · mailto:bjoern@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
Closed Thread


Similar .NET Framework bytes