Node.descendant 和 Node.child 有什么区别?
scala> val n = <a b="c">d</a>.asInstanceOf[xml.Node]
n: scala.xml.Node = <a b="c">d</a>
scala> n.descendant
res22: List[scala.xml.Node] = List(d)
scala> n.child
res23: Seq[scala.xml.Node] = ArrayBuffer(d)
我认为它对于其他元素类型的行为可能有所不同。但它对于 Text 是一样的。
scala> val t = n.child.head.asInstanceOf[xml.Text]
t: scala.xml.Text = d
scala> t.descendant
res24: List[scala.xml.Node] = List()
scala> t.child
res25: object Nil = List()
最佳答案
在 XML 术语中,后裔通常包括 child 或孙子( child 的 child ,等等);而 child 只是一个直接子元素(元素直接包含在父元素中)。
关于xml - 斯卡拉 XML : Descendant vs Child,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4621130/