Preserve whitespaces in XML files

M

Martin Horst

Hi,

I'm using the XmlTextWriter class creating an XML document. In my case
it is necessary that values which are containing only whitespaces are
excatly written into an XML tag. I know that there is the XML attribute
xml:space="preserve". So I tried to add this attribute but nothing
happens. Also I inherited the XmlTextWriter class and overrided the
XmlSpace property. But this didn't work neither. So my question is: Can
I use the XmlTextWriter class for writing whitespaces?

Thanks in advance
Martin
 
J

Jon Skeet [C# MVP]

I'm using the XmlTextWriter class creating an XML document. In my case
it is necessary that values which are containing only whitespaces are
excatly written into an XML tag. I know that there is the XML attribute
xml:space="preserve". So I tried to add this attribute but nothing
happens. Also I inherited the XmlTextWriter class and overrided the
XmlSpace property. But this didn't work neither. So my question is: Can
I use the XmlTextWriter class for writing whitespaces?

Have you tried using XmlWriter.Create, specifying appropriate
XmlWriterSettings (e.g. NewLineHandling=NewLineHandling.None)?

If this doesn't help, could you post a short but complete program
which demonstrates the problem?
See http://pobox.com/~skeet/csharp/complete.html for more on what I
mean by that.

Jon
 
M

Martin Horst

Hi,
Have you tried using XmlWriter.Create, specifying appropriate
XmlWriterSettings (e.g. NewLineHandling=NewLineHandling.None)?

If this doesn't help, could you post a short but complete program
which demonstrates the problem?
See http://pobox.com/~skeet/csharp/complete.html for more on what I
mean by that.

I figured it out. It was not the problem of the XmlWriter class. The XML
document was ok. My problem was that I watched it the XML viewer of the
VS debugger. In the moment I'm fighting against the XmlReader class.


Best regards.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top