I can pass a variable as a multivalued parameter:
scala> <b/>
res26: scala.xml.Elem = <b></b>
scala> Elem(null,"a",Null,TopScope,res26)
res27: scala.xml.Elem = <a><b></b></a>
But I can't pass an XML literal as a multivalued parameter:
scala> Elem(null,"a",Null,TopScope,<b/>)
<console>:12: error: not found: value <
Elem(null,"a",Null,TopScope,<b/>)
But I can pass an XML literal as a simple parameter
scala> def bar(s:String,n:Elem) = s+n.toString
bar: (s: String, n: scala.xml.Elem)java.lang.String
scala> bar("super ", <a/>)
res30: java.lang.String = super <a></a>
?
Thanks
Adding a space before the XML element makes it work:
scala> Elem(null, "a", Null, TopScope, <b/>)
resN: scala.xml.Elem = <a><b></b></a>
From the Scala Language Specification, Section 1.5:
In order to allow literal inclusion of XML fragments, lexical analysis switches from Scala mode to XML mode when encountering an opening angle bracket ’<’ in the following circumstance: The ’<’ must be preceded either by whitespace, an opening parenthesis or an opening brace and immediately followed by a character starting an XML name
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With