473,624 Members | 2,165 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 CreateBasicXmlD ocument()
{
XmlWriterSettin gs writeSettings = new XmlWriterSettin gs();
writeSettings.I ndent = true;
XmlWriter writer = XmlWriter.Creat e( filePath, writeSettings );
writer.WriteSta rtElement("data ");
writer.WriteWhi tespace(" ");
writer.WriteVal ue(" data with leading space");
writer.WriteEnd Element();
writer.Close();
}

Feb 19 '07 #1
4 6047
Steve,

I think you need to set the XmlSpace attribute of the XmlWriter to
XmlSpace.Preser ve.

--BJ

"Steve Richter" wrote:
when I run the following code the leading spaces of the "data" node
are removed. How do I retain whitespace?

private void CreateBasicXmlD ocument()
{
XmlWriterSettin gs writeSettings = new XmlWriterSettin gs();
writeSettings.I ndent = true;
XmlWriter writer = XmlWriter.Creat e( filePath, writeSettings );
writer.WriteSta rtElement("data ");
writer.WriteWhi tespace(" ");
writer.WriteVal ue(" data with leading space");
writer.WriteEnd Element();
writer.Close();
}

Feb 19 '07 #2
On Feb 19, 12:36 pm, BJ Safdie <MSDNNospam...@ nospam.nospamwr ote:
Steve,

I think you need to set the XmlSpace attribute of the XmlWriter to
XmlSpace.Preser ve.
I tried that. the XmlSpace attribute is read only. very confusing!

-Steve

>
--BJ

"Steve Richter" wrote:
when I run the following code the leading spaces of the "data" node
are removed. How do I retain whitespace?
private void CreateBasicXmlD ocument()
{
XmlWriterSettin gs writeSettings = new XmlWriterSettin gs();
writeSettings.I ndent = true;
XmlWriter writer = XmlWriter.Creat e( filePath, writeSettings );
writer.WriteSta rtElement("data ");
writer.WriteWhi tespace(" ");
writer.WriteVal ue(" data with leading space");
writer.WriteEnd Element();
writer.Close();
}- Hide quoted text -

- Show quoted text -

Feb 19 '07 #3
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.WriteSta rtElement("data ");
writer.WriteSta rtElement("inne rdata");
writer.WriteVal ue(" data with leading space");
writer.WriteEnd Element();
writer.WriteEnd Element();
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 CreateBasicXmlD ocument()
{
XmlWriterSettin gs writeSettings = new XmlWriterSettin gs();
writeSettings.I ndent = true;
XmlWriter writer = XmlWriter.Creat e( filePath, writeSettings );
writer.WriteSta rtElement("data ");
writer.WriteWhi tespace(" ");
writer.WriteVal ue(" data with leading space");
writer.WriteEnd Element();
writer.Close();
}



--
Happy coding!
Morten Wennevik [C# MVP]
Feb 19 '07 #4
On Feb 19, 1:01 pm, "Morten Wennevik [C# MVP]"
<MortenWenne... @hotmail.comwro te:
Hi Steve,

The white spaces you add are there. Your code appends a single space character in front
of the value.
your right! <smacks head I was displaying the xml document thru
Windows Explorer -Internet Explorer. Whatever font it was in really
shrunk down the whitespace.

thanks,

-Steve

Feb 20 '07 #5

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

Similar topics

1
2807
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
6037
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 started to use the newest version of Xerces and as a result I stopped using DOMParser. The following fragment of my code shows how I create the parser and parse my XML file, which still has <null> #text fields for whitespace. How can I force...
3
2057
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 the same information, will normalize towards one form. This standard form can then be used as the basis for encryption or digital verification (such as XML Digital Signature). If this is the case, then why is whitespace outside of any tags still...
2
4475
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 nodeValue. Am i missing something? /** * NodeFilter supposed to remove ignorable whitespace */ private class WhiteSpaceFilter implements NodeFilter {
8
2935
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
1940
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 (http://xml.apache.org/xerces-j/apiDocs/org/apache/xerces/dom/TextImpl.html#isIgnorableWhitespace()). I guess when they refer to "ignorable whitespace" in Java we may interpret that as an "insignificant whitespace" in .NET. Am I correct to say that? So, I need to manually convert some Java code to C#,...
9
2553
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 ever come up with a good answer to what seems like such a common question. ...
1
2638
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 XmlWriterSettings(); writeSettings.Indent = true; XmlWriter writer = XmlWriter.Create( filePath, writeSettings );
9
3362
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 = dt.innerHTML + 'new' in Firefox, I get "test textnew"
0
8234
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8172
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8677
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8335
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7158
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6110
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5563
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4079
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2605
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.