Consider this code:
i开发者_运维问答mport scala.xml.{Node,HasKeyValue}
def domatch(x:Node): Node = {
val hasBar = new HasKeyValue("bar")
x match {
case Node("foo", hasBar(z), _*) => z
case _ => null
}
}
When compiling it, I receive the following warning:
error: class HasKeyValue in package xml is deprecated:
Use UnprefixedAttribute's extractor
How should the code look like?
scala> import xml._
import xml._
scala> val hasBar = new HasKeyValue("bar")
<console>:10: warning: class HasKeyValue in package xml is deprecated: Use UnprefixedAttribute's extractor
val hasBar = new HasKeyValue("bar")
^
<console>:10: warning: class HasKeyValue in package xml is deprecated: Use UnprefixedAttribute's extractor
val hasBar = new HasKeyValue("bar")
^
hasBar: scala.xml.HasKeyValue = scala.xml.HasKeyValue@62a28815
scala> <e bar="bar"/> match { case Node(_, hasBar(es), _*) => es }
res0: scala.xml.Node = bar
scala> <e bar="blerg"/> match { case Node(_, UnprefixedAttribute(_, es, _), _*) => es }
res1: Seq[scala.xml.Node] = blerg
精彩评论