我在 scala 中加载一个 XML 文件,如下所示:
<dataset>
<item label="neutral" target="general" tweetid="936466790" username="B_E_X">
<content>Jim Lehrer just directed the debate audience ... 30 seconds ... #tweetdebate</content>
</item>
<item label="neutral" target="general" tweetid="936466992" username="Jonathan Fields">
<content>Here we go. #tweetdebate</content>
</item>
</dataset>
现在,我正在尝试使用属性获取每个项目的标签,但它总是没有返回我?我尝试了几种方法,例如匹配,解析等:
val rawXML = XML.loadFile(file).toList
rawXML.foreach(x => println(x.attribute("label")))
我还尝试了如下匹配:
myXML match {
case <dataset>
{item @ <item>{theText}</item>}
</dataset> =>
println("An %s text: %s".format(item \ "@label", theText))