Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent Scala's XML PrettyPrinter class from removing newlines

Tags:

xml

scala

The PrettyPrinter XML formatter removes newlines from character data. How do I 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.

like image 891
Landon Kuhn Avatar asked Nov 14 '22 00:11

Landon Kuhn


1 Answers

You might try using ConstructingParser to escape your string, as detailed here:

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

like image 164
ZacharyP Avatar answered Jan 31 '23 23:01

ZacharyP