Remove unwanted NewLine characters when using the XmlWriter class

J

JB

Hi All,

I'm writing XML in VB.NET 2005 using the System.Xml.XmlWriter class.
It's all working fine but I'd like to remove a few NewLine characters.

For instance if I use the following code:
Writer.WriteStartElement("Name")
oObject.WriteXml(Writer) 'This object writes it's ow
Writer.WriteEndElement("Name")

The XML produced is (on 3 lines):
<Name>
<CField FieldType="String">Query 2</CField>
</Name>

I would like to get the same XML but on 1 line:
<Name><CField FieldType="String">Some Name</CField></Name>

I tried to use the WriteRaw method of the XmlWriter class, it works
but it requires handling the alignment manually which can become a bit
messy.

Any ideas on how to do that?

Thanks
JB
 
M

mark.milley

Hi JB -

Write the output to a string, then run a quick replace on it. ie:

strVal = strVal.Replace(System.Environment.newline, "")

Good Luck,

-Mark
 

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