【发布时间】:2014-07-01 23:58:51
【问题描述】:
假设我们有一个类似的 XML
<a id="one">
<aa id="one -depth one">
<aaa id="one -depth two">
</aaa>
</aa>
<bb id="two -depth one">
<bbb id="two -depth two">
<bbbb id="bbbb depth three">
</bbbb>
</bbb>
</bb>
</a>
<b id="two"></b>
<c id="three"></c>
<d id="four"></d>
<e id="five"></e>'
然后,我希望通过使用 Scala 的尾递归或任何其他方式获得类似于以下的输出,同时考虑性能和代码质量。节点的深度可以是动态的(不固定,可以到任意深度)
List(
Object(A, List(
Object(AA, List(
Object(AAA, List())
)
),
Object(BB, List(
Object(BBB, List(
Object(BBBB, List())
) )
)
)
)
),
Object(B, List()),
Object(C, List()),
Object(D, List()),
Object(E, List())
)
任何建议甚至某种伪代码都将不胜感激。
【问题讨论】:
-
您的数据来自哪里?您只是想从代码中构造一些任意结构吗?你看scala.xml了吗?
-
也在使用这些库。但是在处理/处理 XML 的动态深度位时遇到了困难。嗯...
-
嗨 nietaki,有没有办法为某些 URL 的 XML 加载设置标头?
标签: xml scala recursion functional-programming tail