如何防止 Scala 的 XML PrettyPrinter 类删除换行符
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>
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试使用 ConstructingParser 来转义字符串,如下所示:
http:// /blog.markfeeney.com/2011/03/scala-xml-gotchas.html
You might try using ConstructingParser to escape your string, as detailed here:
http://blog.markfeeney.com/2011/03/scala-xml-gotchas.html