1

Code and version: .NET Framework 3.5 // vb.net

How I can keep the line break of a string field? The line break is saved in the database with Environment.NewLine

Original string with newline

this is line 1

this is line 2

this is line 3

I am tried the next codes, but no success:

Dim ws As New XmlWriterSettings()
ws.NewLineHandling = NewLineHandling.Entitize
Dim ser As New XmlSerializer(GetType(Facturae))
Using wr As XmlWriter = XmlWriter.Create(_ficheroXML, ws)
  ser.Serialize(wr, fac)
End Using

or

Dim serializer As New XmlSerializer(GetType(Facturae))
Dim xtw As XmlTextWriter = New XmlTextWriter(New StreamWriter(_ficheroXML, False))
serializer.Serialize(xtw, fac)
xtw.Flush()
xtw.Close()

xml output:

<ItemDescription>this is line 1 this is line 2 this is line 3</ItemDescription>
kontable
  • 73
  • 9
  • possible duplicate of [How to keep XmlSerializer from killing NewLines in Strings?](http://stackoverflow.com/questions/2340180/how-to-keep-xmlserializer-from-killing-newlines-in-strings) – Nico Schertler Sep 14 '15 at 11:18
  • I had already seen this article and tested. But no success, returns the code that i put in my question – kontable Sep 14 '15 at 16:21
  • How do you observe that ``? If you do nothing and do not touch or provide xml writer settings, the new lines are preserved. – GSerg Sep 14 '15 at 16:38
  • If you already used that solution, always mention that in your question, then surely you only have an imaginary problem. Caused by looking at the .xml file with a text viewer that cannot properly handle the line endings. Like Notepad. – Hans Passant Sep 14 '15 at 16:43

0 Answers0