jbrave
Channel Surfer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2010
10:39 PM
Re: parsing XML question
Thanks for catching that typo, I was just starting to pull hair(s) out of my head over it.
So I'm now trying to understand the new bit of code you posted,
where did you get FileCount.Count() from, or is that a typo for xmlFileCount?
- Joel
So I'm now trying to understand the new bit of code you posted,
where did you get FileCount.Count() from, or is that a typo for xmlFileCount?
- 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:43 PM
Re: parsing XML question
"jbrave" wrote:
Thanks for catching that typo, I was just starting to pull hair(s) out of my head over it.
So I'm now trying to understand the new bit of code you posted,
where did you get FileCount.Count() from, or is that a typo for xmlFileCount?
- Joel
If you look at section 10.17 in the BrightScriptReferenceManual.pdf, you'll see that roXMLList implements the ifList interface, which is documented in section 10.1. Count() is a method of that interface.
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-11-2010
11:04 PM
Re: parsing XML question
So, you are checking:
xmlFileCount = xml.GetNamedElements("file-count")
' create an roXMLLIst and assign the element file-count to that list (I don't understand this enough to explain it to anyone myself)
If xmlFileCount <> invalid
' check if xmlFileCount is null
And fileCount.Count() > 0
' check if the array variable filecount contains at least one entry (why?)
Then
'assign the value of the field file-count
fileCount = xmlFileCount[ 0 ].GetText()
- Joel
xmlFileCount = xml.GetNamedElements("file-count")
' create an roXMLLIst and assign the element file-count to that list (I don't understand this enough to explain it to anyone myself)
If xmlFileCount <> invalid
' check if xmlFileCount is null
And fileCount.Count() > 0
' check if the array variable filecount contains at least one entry (why?)
Then
'assign the value of the field file-count
fileCount = xmlFileCount[ 0 ].GetText()
- 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
11:12 PM
Re: parsing XML question
"jbrave" wrote:
xmlFileCount = xml.GetNamedElements("file-count")
' create an roXMLLIst and assign the element file-count to that list (I don't understand this enough to explain it to anyone myself)
Give me an roXMLList that contains every "file-count" element below whatever element "xml" references
"jbrave" wrote:
If xmlFileCount <> invalid
' check if xmlFileCount is null
Correct.
"jbrave" wrote:
And fileCount.Count() > 0
' check if the array variable filecount contains at least one entry (why?)
Basically, without testing it, I don't know if GetNamedElements will return invalid or an empty roXMLList, so we check both, so the next line that tries to access the first element of the list doesn't blow up if it's the latter (an empty list)
"jbrave" wrote:
'assign the value of the field file-count
fileCount = xmlFileCount[ 0 ].GetText()
Correct.
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-11-2010
11:37 PM
Re: parsing XML question
Ok, cool. So if I understand it, if there is a bunch of xml like this:
<users type="array">
<user>sammy smith</user>
<file-count>10</file-count>
<user>steve jones</user>
<file-count>40</file-count>
</users>
and I do this:
xmlFileCount = xml.GetNamedElements("file-count")
then I have an array with two entries, xmlFileCount[0] has a value of 10 and xmlFileCount[1] has a value of 40
Would that be an accurate assumption?
- Joel
<users type="array">
<user>sammy smith</user>
<file-count>10</file-count>
<user>steve jones</user>
<file-count>40</file-count>
</users>
and I do this:
xmlFileCount = xml.GetNamedElements("file-count")
then I have an array with two entries, xmlFileCount[0] has a value of 10 and xmlFileCount[1] has a value of 40
Would that be an accurate assumption?
- 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
11:58 PM
Re: parsing XML question
Almost. xmlFileCount is an roXMLList of roXMLElements, so xmlFileCount[0] is an roXMLElement whose GetText() method will return "10".
So, xmlFileCount[0].GetText() is "10" and xmlFileCount[1].GetText() is "40". If you need an integer you can either call:
Both should return the same result, though unless you have absolute certainty that the XML file will always be correct, you'll probably want to check to make sure GetText() actually returns a value first, to be safe.
So, xmlFileCount[0].GetText() is "10" and xmlFileCount[1].GetText() is "40". If you need an integer you can either call:
intFileCount = Int(xmlFileCount[0].GetText()Or
intFileCount = xmlFileCount[0].GetText().ToInt()
Both should return the same result, though unless you have absolute certainty that the XML file will always be correct, you'll probably want to check to make sure GetText() actually returns a value first, to be safe.
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-12-2010
12:20 AM
Re: parsing XML question
Ok, that makes sense. I have one more question, I hope you don't mind answering.
The reason I am getting the file-count variable was to dimension an array for each user with the number of files, each element of the array containing the URL to access each file. Now I realize what I need is a data structure like this:
[0] title, description, url
[1] title, description, url
[2] title, description, url
...
I think the roXMLList is the correct data structure to use, and perhaps all I need is to do something like this
xmlfileList=CreateObject("roXMLElement")
filelist=xmlFileList.Parse(xmlFileList)
and use the xml functions described in section 4.5:
fileTitle=FileList.user.title.GetText()
fileURL=FileList.user.url.GetText()
fileDescription=FileLIst.user.description.GetText
and then call a subroutine or function to display the info and play that file
Would that be accurate syntax (leaving out any tests to make sure the data is valid)
Thanks
- Joel
The reason I am getting the file-count variable was to dimension an array for each user with the number of files, each element of the array containing the URL to access each file. Now I realize what I need is a data structure like this:
[0] title, description, url
[1] title, description, url
[2] title, description, url
...
I think the roXMLList is the correct data structure to use, and perhaps all I need is to do something like this
xmlfileList=CreateObject("roXMLElement")
filelist=xmlFileList.Parse(xmlFileList)
and use the xml functions described in section 4.5:
fileTitle=FileList.user.title
fileURL=FileList.user.url
fileDescription=FileLIst.user.description
and then call a subroutine or function to display the info and play that file
Would that be accurate syntax (leaving out any tests to make sure the data is valid)
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-12-2010
12:29 AM
Re: parsing XML question
Parse() actually returns a boolean that indicates whether the XML was correctly parsed, so you would reference xmlFileList as the root object instead of filelist. I think you probably want something more like this:
Assuming your XML is like this:
xmlfileList=CreateObject("roXMLElement")
If xmlFileList.Parse(xmlFileList) Then
For Each user in xmlFileList.user
fileTitle = user.title[x].GetText()
fileURL = user.url[x].GetText()
fileDescription = user.description[x].GetText()
' Do your user specific processing
Next
End If
Assuming your XML is like this:
<users>
<user>
<title>MyTitle</title>
<url>http://blah.blah</url>
<description>blah blah blah</description>
</user>
<user>
<title>MyTitle</title>
<url>http://blah.blah</url>
<description>blah blah blah</description>
</user>
</users>
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-12-2010
12:40 AM
Re: parsing XML question
Yes, that is about the structure of the XML.
Well I tried implementing what you described in your previous posts, but I'm getting an error thrown, see asterisks in the code below:
/tmp/plugin/HGAAAAhOIGYV/pkg:/source/main.brs(85): runtime error ec: 'Dot' Operator attempted with invalid BrightScript Component or interface reference.
085: If xmlFileCount <> invalid And FileCountString.Count() > 0 Then
If I leave out all the testing and use this:
FileCountString=xml.GetNamedElements("file-count")[0].GetText()
it works just fine. The code:
xfer.setURL(api+resource+user+uresource+ckey)
xferResult = xfer.GetToString()
print "transfer-result"+xferResult
'ok, now we have the user info, we need the number of files that user has
if xml.Parse(xferResult)
'from user info get number of Files
xmlFileCount = xml.GetNamedElements("file-count")
****** If xmlFileCount <> invalid And FileCountString.Count() > 0 Then
FileCountString = xmlFileCount[0].GetText()
End If
print FileCountString
FileCountNumeric=val(FileCountString)
print FileCountNumeric
print type(FileCountNumeric)
end if
End Sub
Well I tried implementing what you described in your previous posts, but I'm getting an error thrown, see asterisks in the code below:
/tmp/plugin/HGAAAAhOIGYV/pkg:/source/main.brs(85): runtime error ec: 'Dot' Operator attempted with invalid BrightScript Component or interface reference.
085: If xmlFileCount <> invalid And FileCountString.Count() > 0 Then
If I leave out all the testing and use this:
FileCountString=xml.GetNamedElements("file-count")[0].GetText()
it works just fine. The code:
xfer.setURL(api+resource+user+uresource+ckey)
xferResult = xfer.GetToString()
print "transfer-result"+xferResult
'ok, now we have the user info, we need the number of files that user has
if xml.Parse(xferResult)
'from user info get number of Files
xmlFileCount = xml.GetNamedElements("file-count")
****** If xmlFileCount <> invalid And FileCountString.Count() > 0 Then
FileCountString = xmlFileCount[0].GetText()
End If
print FileCountString
FileCountNumeric=val(FileCountString)
print FileCountNumeric
print type(FileCountNumeric)
end if
End Sub
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-12-2010
01:07 AM
Re: parsing XML question
In your If statement, you should be checking Count() on xmlFileCount, not on FileCountString.
Hate to abandon you, but it's 4am here, and I've got a 5 year old's party to go to in a few hours, so I need to hit the sack. Good luck!
If xmlFileCount <> invalid And xmlFileCount.Count() > 0 Then
Hate to abandon you, but it's 4am here, and I've got a 5 year old's party to go to in a few hours, so I need to hit the sack. Good luck!
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)