Elem(prefix, label, attribs, scope, child) 方法在 Scala 2.10 中被弃用,应该使用 Elem(prefix, label, attribs, scope, minimizeEmpty, child)。但是,至少在空元素上,新的 apply 方法具有不同的行为。不推荐使用的版本以这种方式工作:
val inputXML = <PC Price="100" CurrencyCode="USD"/>
val rule1 = new RewriteRule {
override def transform(n: Node): Seq[Node] = n match {
case Elem(prefix, "PC", attribs, scope, content @ _*) =>
Elem(prefix, "Mac", attribs, scope, content:_*)
case other => other
}
}
println(new RuleTransformer(rule1).transform(inputXML))
打印:
List(<Mac Price="100" CurrencyCode="USD"/>)
但是当使用新的 Elem 方法时,匹配不起作用:
val inputXML = <PC Price="100" CurrencyCode="USD"/>
val rule1 = new RewriteRule {
override def transform(n: Node): Seq[Node] = n match {
case Elem(prefix, "PC", attribs, scope, minimizeEmpty, content @ _*) =>
Elem(prefix, "Mac", attribs, scope, true, content:_*)
case other => other
}
}
println(new RuleTransformer(rule1).transform(inputXML))
上面的代码返回:
<PC Price="100" CurrencyCode="USD"/>
这是一个错误还是我做错了什么?我正在使用 Scala 2.10.2。
谢谢,