开发者

How to migrate code from HasKeyValue to UnprefixedAttribute?

开发者 https://www.devze.com 2023-03-25 09:19 出处:网络
Consider this code: i开发者_运维问答mport scala.xml.{Node,HasKeyValue} def domatch(x:Node): Node = {

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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号