Remove unwanted NewLine characters when using the XmlWriter class

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • JB

    Remove unwanted NewLine characters when using the XmlWriter class

    Hi All,

    I'm writing XML in VB.NET 2005 using the System.Xml.XmlW riter 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.WriteSta rtElement("Name ")
    oObject.WriteXm l(Writer) 'This object writes it's ow
    Writer.WriteEnd Element("Name")

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

    I would like to get the same XML but on 1 line:
    <Name><CField FieldType="Stri ng">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

  • mark.milley@binaryswitch.com

    #2
    Re: Remove unwanted NewLine characters when using the XmlWriter class

    Hi JB -

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

    strVal = strVal.Replace( System.Environm ent.newline, "")

    Good Luck,

    -Mark

    Comment

    Working...