开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜