Scala seems to do two things to XML that you enter that make it no less parseable but make it less readable:
Scala似乎对您输入的XML做了两件事,使其具有同样的解析性,但使其可读性更差:
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?)
这些合并使得XML的可读性大大降低(至少在我看来是这样)。我不太熟悉XML库;是否有一种方法可以执行xml到字符串的转换,从而产生紧凑的人类可读的表单?(如果不是默认情况下,通过递归和编写自己的字符串转换——或者是否有太多的特殊情况潜伏在那里?)
1 个解决方案
#1
6
Mostly, see scala.xml.Utility.toXml
. The attribute thing doesn't have a solution, though (as far as I know).
大多数情况下,看到scala.xml.Utility.toXml。但是属性方面没有解决方案(据我所知)。
scala> xml.Utility.toXML(<a/>, minimizeTags = true)
res13: StringBuilder = <a />
You may want to look at scala.xml.PrettyPrinter
as well.
您可能需要查看scala.xml。PrettyPrinter。
#1
6
Mostly, see scala.xml.Utility.toXml
. The attribute thing doesn't have a solution, though (as far as I know).
大多数情况下,看到scala.xml.Utility.toXml。但是属性方面没有解决方案(据我所知)。
scala> xml.Utility.toXML(<a/>, minimizeTags = true)
res13: StringBuilder = <a />
You may want to look at scala.xml.PrettyPrinter
as well.
您可能需要查看scala.xml。PrettyPrinter。