Scala:XML属性解析 [英] Scala: XML Attribute parsing

查看:94
本文介绍了Scala:XML属性解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为属性"date"解析一个看起来像这样的rss feed:

I'm trying to parse a rss feed that looks like this for the attribute "date":

<rss version="2.0">
<channel>
    <item>
        <y:c date="AA"></y:c>
    </item>
</channel>
</rss>

我尝试了几种不同的版本:(rssFeed包含RSS数据)

I tried several different versions of this: (rssFeed contains the RSS data)

println(((rssFeed \\ "channel" \\ "item" \ "y:c" \"date").toString))

但是似乎没有任何效果.我想念什么?

But nothing seems to work. What am I missing?

任何帮助将不胜感激!

推荐答案

<y:c中的"y"是名称空间前缀.它不是名称的一部分.同样,属性以"@"表示.试试这个:

The "y" in <y:c is a namespace prefix. It's not part of the name. Also, attributes are referred to with a '@'. Try this:

println(((rssFeed \\ "channel" \\ "item" \ "c" \ "@date").toString))

这篇关于Scala:XML属性解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆