jbrave
Channel Surfer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2010
12:30 AM
parsing XML question
I'm getting an xml feed and trying to extract some data. With tags like
<name>Joseph</name>
it works just fine.
but with With tags like:
<file-count type="Integer">30</file-count>
I get this error:
/tmp/plugin/HJAAAAREIkOr/pkg:/source/main.brs(33): runtime error ec: 'Dot' Operator attempted with invalid BrightScript Component or interface reference.
033: tcs=xml.file-count.GetText()
and:
tcs &h30 Untyped val:Uninitialized
Can anyone help? How do get the value of a tag that has subsidiary information in it like "type"? Should I declare tcs as an integer first? It doesn't seem to help. Do I need to do a test of some kind on each xml key before I attempt to assign it to a variable?
Thanks!
<name>Joseph</name>
it works just fine.
but with With tags like:
<file-count type="Integer">30</file-count>
I get this error:
/tmp/plugin/HJAAAAREIkOr/pkg:/source/main.brs(33): runtime error ec: 'Dot' Operator attempted with invalid BrightScript Component or interface reference.
033: tcs=xml.file-count.GetText()
and:
tcs &h30 Untyped val:Uninitialized
Can anyone help? How do get the value of a tag that has subsidiary information in it like "type"? Should I declare tcs as an integer first? It doesn't seem to help. Do I need to do a test of some kind on each xml key before I attempt to assign it to a variable?
Thanks!
Screenshades: The first Screensaver for Roku2!
Musiclouds: The best free internet music, on your Roku!
Ouroborialis: Psychedelic Screensaver for Roku!
Musiclouds: The best free internet music, on your Roku!
Ouroborialis: Psychedelic Screensaver for Roku!
37 REPLIES 37
kbenson
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2010
12:41 AM
Re: parsing XML question
"-" is not a valid variable character. Use one of the alternate access methods, such as a member function, to access the element. The Reference manual mentions this when referring to the need to do case sensitive matching, so it will most likely work here as well.
-- GandK Labs
Check out Reversi! in the channel store!
Check out Reversi! in the channel store!
jbrave
Channel Surfer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2010
12:56 AM
Re: parsing XML question
Ok, looks like you are correct that the - is the cause of the problem. Now how do I get that xml tag without using the dash character - it is in the xml feed and there are many other xml tags that have that character as well
Screenshades: The first Screensaver for Roku2!
Musiclouds: The best free internet music, on your Roku!
Ouroborialis: Psychedelic Screensaver for Roku!
Musiclouds: The best free internet music, on your Roku!
Ouroborialis: Psychedelic Screensaver for Roku!

TheEndless
Channel Surfer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2010
01:02 AM
Re: parsing XML question
The roXMLElement component has a GetNamedElements() method. You should be able to use that to get an roXMLList of the "file-count" elements that you can loop through.
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)
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
jbrave
Channel Surfer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2010
01:11 AM
Re: parsing XML question
Thanks for responding. I don't see any examples of actual usage of GetNamedElement in the documentation. I'm searching through the examples also, and the videoplayer which actually parses XML doesn't use this function. Can you post an example of how GetNamedElement is actually used?
Screenshades: The first Screensaver for Roku2!
Musiclouds: The best free internet music, on your Roku!
Ouroborialis: Psychedelic Screensaver for Roku!
Musiclouds: The best free internet music, on your Roku!
Ouroborialis: Psychedelic Screensaver for Roku!
hoffmcs
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2010
04:40 AM
Re: parsing XML question
In your case it would be:
xml.GetNamedElement("file-count")[0].GetText()
jbrave
Channel Surfer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2010
02:13 PM
Re: parsing XML question
Thanks! So, how would one know that a function like GetNamedElement would be called like this, as opposed to xml.tagname.GetNamedElement() ?
What do I look for when reading the Developer manual to know if a function gets called like:
something.Function() or if it gets called like:
Function("something")
In other words, how did you come up with that statement and know that it works?
- Joel
What do I look for when reading the Developer manual to know if a function gets called like:
something.Function() or if it gets called like:
Function("something")
In other words, how did you come up with that statement and know that it works?
- Joel
Screenshades: The first Screensaver for Roku2!
Musiclouds: The best free internet music, on your Roku!
Ouroborialis: Psychedelic Screensaver for Roku!
Musiclouds: The best free internet music, on your Roku!
Ouroborialis: Psychedelic Screensaver for Roku!
hoffmcs
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2010
02:24 PM
Re: parsing XML question
It is documented in the SDK. Look at section 10.16 in the Brightscript Reference Manual. There are also some examples in the generalUtil.brs files found in some of the example channels.
jbrave
Channel Surfer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2010
09:47 PM
Re: parsing XML question
Thanks, I read the manual section you suggested again, and I understand a little bit better now. However, I still don't understand all the aspects of that code you posted. What is the [0] about, seems like an array reference, but why is it needed when there is already the name of the tag in the parenthesis:
xml.GetNamedElement("file-count")[0].GetText()
Thanks,
Joel
xml.GetNamedElement("file-count")[0].GetText()
Thanks,
Joel
Screenshades: The first Screensaver for Roku2!
Musiclouds: The best free internet music, on your Roku!
Ouroborialis: Psychedelic Screensaver for Roku!
Musiclouds: The best free internet music, on your Roku!
Ouroborialis: Psychedelic Screensaver for Roku!

TheEndless
Channel Surfer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2010
10:02 PM
Re: parsing XML question
"jbrave" wrote:
Thanks, I read the manual section you suggested again, and I understand a little bit better now. However, I still don't understand all the aspects of that code you posted. What is the [0] about, seems like an array reference, but why is it needed when there is already the name of the tag in the parenthesis:
xml.GetNamedElement("file-count")[0].GetText()
Thanks,
Joel
The name of the method is actually GetNamedElements and it returns an roXMLList, so you need to get the first index of that list to get the XML element you're looking for. The safest way to do this is probably...
xmlFileCount = xml.GetNamedElements("file-count")
If xmlFileCount <> invalid And fileCount.Count() > 0 Then
fileCount = xmlFileCount[ 0 ].GetText()
End If
With that, you won't blow up if the element is missing from your XML for some reason.
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)
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)