Your Digital Media Has Never Looked So Good

 
jbrave
Topic Author
Posts: 716
Joined: Mon Mar 22, 2010 3:00 pm
Location: Ben Lomond, CA
Contact:

colon in xml tag?

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!
 
User avatar
TheEndless
** Valued Community Member **
Posts: 9218
Joined: Mon Oct 04, 2004 10:15 am
Location: US
Contact:

Re: colon in xml tag?

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), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
 
User avatar
RokuChris
Posts: 1161
Joined: Mon Aug 30, 2010 1:45 pm

Re: colon in xml tag?

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"]
 
jbrave
Topic Author
Posts: 716
Joined: Mon Mar 22, 2010 3:00 pm
Location: Ben Lomond, CA
Contact:

Re: colon in xml tag?

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!

Who is online

Users browsing this forum: btpoole and 2 guests