开发者

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

开发者 https://www.devze.com 2023-02-26 19:45 出处:网络
The PrettyPrinter XML formatter removes newlines from character data. How do I prevent this? scala> import scala.xml._

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)))
开发者_JS百科res1: String = <multiline><![CDATA[line one line two]]></multiline>

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


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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消