Groups | Blog | Home
all groups > dotnet xml > august 2004 >

dotnet xml : whitespace in empty nodes after save


frostbox NO[at]SPAM hotmail.com
8/26/2004 4:36:49 AM
Loading and saving a xml document in .net creates whitespace in empty nodes!

loading an empty node like:

<node></node>

..net saves as:

<node>
</node>

resulting in a whitespace when processed by xslt like:

<xsl:value-of select="node"/>


Can the whitespace be removed from empty nodes before saving in .net ??

Peter Theill
8/26/2004 1:47:05 PM
[quoted text, click to view]
nodes!

Set the "PreserveWhitespace" attribute on your document to true, e.g.

XmlDocument d = new XmlDocument();
d.PreserveWhitespace = true;
d.Load("file.xml");

// do your processing...

d.Save("file2.xml");



Rgd,
Peter Theill

Clark Spencer
8/30/2004 4:41:02 AM
I have the same issue as Mr Frost.
I tried your solution (using the PreServeWhiteSpace property of the
XmlDocument) and it made no sence to me?

The XmlParser removes ALL carridge return in the entire document. I just
want to remove the extra carridge return added in empty elements. It seems
Michael Frost wanted the same.

Is it possible to remove that extra carridge return in empty elements?

Regards,

/Clark

[quoted text, click to view]
specialagent.mulder NO[at]SPAM gmx.net
8/30/2004 11:32:01 PM
Hi,

I have exactly the same problem - do you have a solution already? The
workaround with PreserveWhitespace works, but I don't want to loose
all carriage returns.

Best regards,
AddThis Social Bookmark Button