如何防止Scala的XML PrettyPrinter类删除换行符

时间:2011-04-19 17:49:15

标签: xml scala

PrettyPrinter XML格式化程序从字符数据中删除换行符。我该如何防止这种情况?

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>

另见https://lampsvn.epfl.ch/trac/scala/ticket/4303

1 个答案:

答案 0 :(得分:1)

您可以尝试使用ConstructingParser来转义字符串,详见此处:

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