开发者

Scala method to pretty print XML directly to a java.io.Writer (not a string)?

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 s开发者_开发技巧equence 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.


I wrote a PrettyPrinter that can directly write to a given file: XMLPrettyPrinter

I use it in production.


scala.xml.PrettyPrinter.format(Node,StringBuilder) could be abused by redirecting the append calls to the writer ... However, this depends heavily on the current implementation of PrettyPrinter, so this is a non-answer ;-)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜