我在前面看到了以下示例,其中的目标是返回包含属性为X且包含值Y的属性的所有节点:
//find all nodes with an attribute "class" that contains the value "test"
val xml = XML.loadString( """<div>
<span class="test">hello</span>
<div class="test"><p>hello</p></div>
</div>""" )
def attributeEquals(name: String, value: String)(node: Node) =
{
node.attribute(name).filter(_==value).isDefined
}
val testResults = (xml \\ "_").filter(attributeEquals("class","test"))
//prints: ArrayBuffer(
//<span class="test">hello</span>,
//<div class="test"><p>hello</p></div>
//)
println("testResults: " + testResults)
Run Code Online (Sandbox Code Playgroud)
我正在使用Scala 2.7,每次返回打印值始终为空.有人可以提供帮助吗?对不起,如果我正在复制另一个线程......但是如果我发布一个新线程,它会更加明显?