colon in xml tag?

Roku's free SDK allows developers to build channels and applications and publish them to the Roku Channel Store. Register for the Developer Program at http://www.roku.com/developer

Moderators: RokuDouglas, RokuRyan, RokuJamesL, RokuKen, RokuChris, RokuJoel

colon in xml tag?

Postby jbrave » Fri Nov 05, 2010 4:42 pm

Anyone know how to get and parse an xml tag that has a colon in it like this:

<media:thumbnail xmlns:media='http://something.something.com/mrss/' url='http://blahblablah.com' width='72' height='72' />

Weird thing is that the data is inside the tag, not inbetween <> and </> like normal tags...

- Joel
Screenshades: The first Screensaver for Roku2!
Musiclouds: The best free internet music, on your Roku!
Ouroborialis: Psychedelic Screensaver for Roku!
jbrave
 
Posts: 716
Joined: Mon Mar 22, 2010 3:00 pm
Location: Ben Lomond, CA

Re: colon in xml tag?

Postby TheEndless » Fri Nov 05, 2010 4:57 pm

I'm not sure what you mean by "weird thing" but...

The part before the colon (media) is the namespace as defined by the "xmlns:media" attribute. It's essentially a way of making a common tag name unique, and associate it with a specific data source. I haven't parsed an XML document with namespaces in BrightScript, but I'd think you would be able to get it with GetNamedElements().

The values I think you're talking about (url, width, and height) are attribute values. You'd access them using @. (ex. xmlElement@url, xmlElement@width, etc). There are examples in the "working with XML" section of the BrightScript reference.
Last edited by TheEndless on Fri Nov 05, 2010 5:17 pm, edited 1 time in total.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), MainSqueeze (MAINSQUEEZE), iTunes Podcasts (ITPC), Justin.tv (JUSTINTV), My Channels (MYCHANNELS)
User avatar
TheEndless
** Valued Community Member **
 
Posts: 7972
Joined: Mon Oct 04, 2004 10:15 am
Location: US

Re: colon in xml tag?

Postby RokuChris » Fri Nov 05, 2010 5:13 pm

jbrave wrote:Anyone know how to get and parse an xml tag that has a colon in it like this:

<media:thumbnail xmlns:media='http://something.something.com/mrss/' url='http://blahblablah.com' width='72' height='72' />

  • To access elements with namespaces, use elementArray = GetNamedElements("media:thumbnail")
  • To access attributes without namespaces, you can use the @ operator. element@url
  • For attributes with namespaces, you would need to say element.GetAttributes()["xmlns:media"]
User avatar
RokuChris
 
Posts: 1086
Joined: Mon Aug 30, 2010 1:45 pm

Re: colon in xml tag?

Postby jbrave » Sat Nov 06, 2010 6:07 pm

By weird I meant I hadn't encountered this style of before in the parsing projects I've undertaken. Anyway, got it working using GetNamedElements("media:thumbnail") and then GetAttributes()

Thanks!

- Joel
Screenshades: The first Screensaver for Roku2!
Musiclouds: The best free internet music, on your Roku!
Ouroborialis: Psychedelic Screensaver for Roku!
jbrave
 
Posts: 716
Joined: Mon Mar 22, 2010 3:00 pm
Location: Ben Lomond, CA


Return to Roku Developer Program

Who is online

Users browsing this forum: No registered users and 6 guests