2011-07-31 58 views
0

考慮以下代碼:如何將代碼從HasKeyValue遷移到UnprefixedAttribute?

import scala.xml.{Node,HasKeyValue} 

    def domatch(x:Node): Node = { 
    val hasBar = new HasKeyValue("bar") 

    x match { 
     case Node("foo", hasBar(z), _*) => z 
     case _ => null 
    } 
    } 

當編譯它,我收到以下警告:

error: class HasKeyValue in package xml is deprecated: 
     Use UnprefixedAttribute's extractor 

應該如何的代碼是什麼樣子?

回答

2
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 = [email protected] 

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

Mhh,但現在我不僅與屬性「bar」匹配...... – soc