【发布时间】:2015-02-11 06:40:39
【问题描述】:
我看到了前面讨论过的以下示例,其目标是返回所有包含 id 为 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)
我使用的是 Scala 2.7,每次返回的打印值总是空的。任何人都可以帮忙吗? 抱歉,如果我正在复制另一个线程...但我认为如果我发布一个新线程会更明显?
【问题讨论】: