When declaring a node sequence in Scala as literals, you get a variable scala.xml.NodeBuffer(it expands ArrayBuffer[scala.xml.Node], which in turn expands Seq[scala.xml.Node]):
scala> val xml = <a /><b />
xml: scala.xml.NodeBuffer = ArrayBuffer(<a></a>, <b></b>)
scala> xml += <c />
res46: xml.type = ArrayBuffer(<a></a>, <b></b>, <c></c>)
scala> xml
res47: scala.xml.NodeBuffer = ArrayBuffer(<a></a>, <b></b>, <c></c>)
This contradicts Scala's philosophy of using immutable objects and functional programming. Why are collections immutable by default, but XML literals (which are first class citizens) are not in this case?
However, is it safe to define an immutable node sequence using XML literals?
source
share