Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
360tv
Streaming Star

Trouble getting an XML Element

I have the following...


<imagesXML>
<channel>
<item><media:content url="http://s3.amazonaws.com/bucket/1.jpg" medium="image"/></item>
<item><media:content url="http://s3.amazonaws.com/bucket/2.jpg" medium="image"/></item>
<item><media:content url="http://s3.amazonaws.com/bucket/3.jpg" medium="image"/></item>
</channel>
</imagesXML>


I need to get the url of the second url attribute.

imagesXML.channel.item.count() works but media@content or media.content@url wont. media:content@url is invalid syntax (of course). I cannot change the XML.
0 Kudos
3 REPLIES 3
TheEndless
Channel Surfer

Re: Trouble getting an XML Element

You'll need to user getNamedElement() to get nodes with namespaces. You may need to break it into multiple statements, but something like this should work:
xml.channel.item[0].getNamedElements("media:content")[0]@url
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
EnTerr
Roku Guru

Re: Trouble getting an XML Element

"TheEndless" wrote:
You'll need to user getNamedElement() to get nodes with namespaces. You may need to break it into multiple statements, but something like this should work:
xml.channel.item[0].getNamedElements("media:content")[0]@url

Actually can do it even simpler, because ifXMLList supports getNamedElements() just like ifXMLElement does (i.e. no need to zero-in on the exact element just yet)
xml.channel.item.getNamedElements("media:content") 
But then will still have to add `[idx]@url` for the specific attribute as needed - because GetAttributes() does not work the same way for ifXMLList, so one cannot do
xml.channel.item.getNamedElements("media:content").getAttributes().url   'No good
xml.channel.item.getNamedElements("media:content")@url 'No good
'but this will do
xml.channel.item.getNamedElements("media:content")[idx]@url 'OK with single row

I like to give credit to roXML when it deserves it: it has some... affordances 🙂
0 Kudos
360tv
Streaming Star

Re: Trouble getting an XML Element

Thanks a lot! Works perfectly.
0 Kudos