Scala 方法将 XML 直接漂亮地打印到 java.io.Writer(不是字符串)?
scala.xml.XML.write 方法支持将 XML 节点序列输出到 java.io.Writer,例如在 servlet 响应中。然而,它似乎没有以漂亮的打印格式输出 XML 的选项。是否有任何 Scala 标准库函数可以将 XML 节点序列漂亮地打印到 java.io.Writer?
注意:scala.xml.PrettyPrinter 似乎不是答案,因为它只返回一个字符串。漂亮的打印机需要直接输出到 java.io.Writer。
The scala.xml.XML.write method supports outputting an XML node sequence to a java.io.Writer, for example in a servlet response. However, it doesn't seem to have an option to output the XML in pretty printed format. Is there any Scala standard library function to pretty print an XML node sequence to a java.io.Writer?
Note: scala.xml.PrettyPrinter does not seem to be the answer because it only returns a string. The pretty printer would need to output directly to a java.io.Writer.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我编写了一个 PrettyPrinter ,可以直接写入给定文件: XMLPrettyPrinter
我在生产中使用它。
I wrote a PrettyPrinter that can directly write to a given file: XMLPrettyPrinter
I use it in production.
scala.xml.PrettyPrinter.format(Node,StringBuilder) 可能会通过将
append
调用重定向到编写器来滥用...但是,这在很大程度上取决于当前的实现PrettyPrinter,所以这是一个非答案;-)scala.xml.PrettyPrinter.format(Node,StringBuilder)
could be abused by redirecting theappend
calls to the writer ... However, this depends heavily on the current implementation of PrettyPrinter, so this is a non-answer ;-)