473,388 Members | 1,335 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

retaining leading whitespace in text of an xml node

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();
}

Feb 19 '07 #1
1 2618
* Steve Richter wrote in microsoft.public.dotnet.xml:
>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:bj****@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/
Feb 21 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: JayC | last post by:
Hey guys, I've noticed that if you have an XML snippet structured like this (I'm using square brackets instead in case it messes up and HTML readers): Blah Blah 2
1
by: John | last post by:
I have been trying with no result, to force Xerces parsers to ignore whitespace in my XML file. I have tried several of the NG suggested setFeature() methods in DOMParser to no avail. I have now...
3
by: Celedor | last post by:
If I understand correctly, canonicalized XML is a simplified, or rather, "standardized" form of XML. It is in such a form such that two documents that are written in different ways, but contain...
2
by: Wired Earp | last post by:
I've had some luck using string values "\t" "\n" and "\r" to insert tabs, newlines and carriagereturn textnodes into a document, but I can't *read* these nodes, at least not by analyzing the...
8
by: Tjerk Wolterink | last post by:
Hello all, how does xsl handle white space? I know you can set domething like this for nice indentation: <xsl:output method="xhtml" indent="yes"/> But know i have xsl code like this:
2
by: Carlitos | last post by:
Hi there, A class in Xerces J-API (Java) called TextImpl contains a property that returns whether the text is ignorable whitespace...
2
by: Carlitos | last post by:
Hi there, A class in Xerces J-API (Java) called TextImpl contains a property that returns whether the text is ignorable whitespace...
9
by: amattie | last post by:
Does anyone have any idea on how I can strip the extra whitespace in the XML that shows up when I receive a response from an ASP.NET 2.0 webservice? This has been discussed before, but no one has...
4
by: Steve Richter | last post by:
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...
9
by: martymix | last post by:
simple question: I have a simple <dt>test text</dt> I get the innerHTML of that dt, and I try and append some text to it like so: dt = document.getElementsByTagName('dt') var text =...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.