我可以将变量作为多值参数传递:
scala> <b/> res26: scala.xml.Elem = <b></b> scala> Elem(null,"a",Null,TopScope,res26) res27: scala.xml.Elem = <a><b></b></a>
但我无法将XML文本作为多值参数传递:
scala> Elem(null,<b/>) <console>:12: error: not found: value < Elem(null,<b/>)
但我可以将XML文本作为简单参数传递
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>
?
谢谢
在XML元素之前添加空格使其工作:
原文链接:https://www.f2er.com/xml/292076.htmlscala> Elem(null,<b/>) resN: scala.xml.Elem = <a><b></b></a>
从Scala Language Specification,第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