Scala seems to do two things to XML that you enter that make it no less parseable but make it less readable:
First, it expands tags that close themselves:
开发者_高级运维scala> <tag/>
res109: scala.xml.Elem = <tag></tag>
And second, it scrambles attributes into random order, as if it put them into a hash set:
scala> <tag a="a" b="b" c="c" d="d"/>
res110: scala.xml.Elem = <tag d="d" a="a" c="c" b="b"></tag>
Together, these conspire to render XML considerably less human-readable (at least by me). I'm not very familiar with the XML library; is there a way to perform xml-to-string translation that yields a compact human-readable form? (If not by default, by recursing and writing one's own string conversions--or are there too many special cases that lurk there?)
Mostly, see scala.xml.Utility.toXml
. The attribute thing doesn't have a solution, though (as far as I know).
scala> xml.Utility.toXML(<a/>, minimizeTags = true)
res13: StringBuilder = <a />
You may want to look at scala.xml.PrettyPrinter
as well.
精彩评论