Scala XML API: Why allow NodeSeq as attribute values?
- by Synesso
It seems attribute values are of type Seq[Node].
scala> <a b="1"/>.attribute("b")
res11: Option[Seq[scala.xml.Node]] = Some(1)
This means you can assign XML as an attribute value.
scala> <a b={<z><x/></z>}/>.attribute("b")
res16: Option[Seq[scala.xml.Node]] = Some(<z><x></x></z>)
scala> <a b={<z><x/></z>}/>.attribute("b").map(_ \ "x")
res17: Option[scala.xml.NodeSeq] = Some(<x></x>)
scala> new xml.PrettyPrinter(120, 2).format(<a b={<z><x/></z>}/>)
res19: String = <a b="<z><x></x></z>"></a>
This seems funky to me. I've never seen XML as attribute values in the real world. Why is it allowed? Why is an attribute value simply not of type String?