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>
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?
Any help would really be appreciated!
Think about using sequence comprehensions, too. They're useful for dealing with XML, particularly if you need complicated conditions.
For the simple case:
Gives you the date attribute from everything in rssFeed.
But if you want something more complex:
Gives you:
Also, think about the difference between \ and \\. \\ looks for a descendent, not just a child, like this (note that it jumps from channel to c, without item):
Or this sort of thing if you just want all the < c > elements, and don't care about their parents:
And this specifies an exact path:
Attributes are retrieved using the "@attrName" selector. Thus, your selector should actually be something like the following:
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: