Human readable XML output from Scala?

Scala seems to do two things for the XML you enter that make it no less understandable, but make it less readable:

First, it extends tags that close themselves:

scala> <tag/> res109: scala.xml.Elem = <tag></tag> 

And secondly, it scrambles the attributes in random order, as if it were putting them in 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, they conspire to make XML much less readable (at least by me). I am not very familiar with the XML library; is there any way to do an xml-to-string translation that gives a compact readable form? (If not by default, by recursing and writing your own string conversions - or are there too many special cases that are hiding there?)

+7
source share
1 answer

Basically see scala.xml.Utility.toXml . The attribute has no solution, though (as far as I know).

 scala> xml.Utility.toXML(<a/>, minimizeTags = true) res13: StringBuilder = <a /> 

You can also look at scala.xml.PrettyPrinter .

+6
source

All Articles