How to prevent the Scala XML PrettyPrinter class from deleting newlines

XML formatting PrettyPrinterremoves newline characters from character data. How to prevent this?

scala> import scala.xml._
import scala.xml._

scala> """line one
     | line two"""
res0: java.lang.String = 
line one
line two

scala> new PrettyPrinter(999, 3).format(Elem(null, "multiline", Null, TopScope, PCData(res0)))
res1: String = <multiline><![CDATA[line one line two]]></multiline>

Also see https://lampsvn.epfl.ch/trac/scala/ticket/4303 .

+5
source share
1 answer

You can try using ConstructingParser to avoid your string, as described here:

http://blog.markfeeney.com/2011/03/scala-xml-gotchas.html

+1
source

All Articles