Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala: XML Attribute parsing

Tags:

parsing

xml

scala

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!

like image 666
Chris Avatar asked May 17 '10 17:05

Chris


2 Answers

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))
like image 78
sblundy Avatar answered Sep 16 '22 11:09

sblundy


Attributes are retrieved using the "@attrName" selector. Thus, your selector should actually be something like the following:

println((rssFeed \\ "channel" \\ "item" \ "c" \ "@date").text)
like image 29
Daniel Spiewak Avatar answered Sep 17 '22 11:09

Daniel Spiewak