加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

在XML中将XML文本作为参数编写

发布时间:2020-12-16 23:49:54 所属栏目:百科 来源:网络整理
导读:我可以将变量作为多值参数传递: scala b/res26: scala.xml.Elem = b/bscala Elem(null,"a",Null,TopScope,res26)res27: scala.xml.Elem = ab/b/a 但我无法将XML文本作为多值参数传递: scala Elem(null,b/)console:12: error: not found: value Elem(null,b
我可以将变量作为多值参数传递:
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元素之前添加空格使其工作:
scala> 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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读