Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
btpoole
Level 7

Filter Array

I attempting to create an array based on multiple xml files then filter the array based on one of the elements of the array. Initially I start by creating one array to combine data from all of the xml files. The first code loops thru an array m.guide based on the number of elements I have stored in guidecount. It takes each element which is a url to an xml file on my server, puts it thru UrlTransfer (done in cURLGUIDE(cid)) function not shown. This creates the xml element. I loop thru this xml to add to array xmlguide.


'**********************BUILD INITIAL ARRAY****************************************************
xmlguide=[]
y=0 'programs in file
x=0 'xml file

cid=m.guide[x]
xml=cURLGUIDE(cid)
while x < guidecount - 1
for each programme in xml.programme
xmlguide.Push({
programme: {date: xml.programme@start}
programme: {title: xml.programme.title.gettext()}
programme: {desc: xml.programme.desc.gettext()}

})

end for
x=x+1
if x>guidecount-1
exit while
else
cid=m.guide[x]
xml=cURLGUIDE(cid)
end if
end while

?"TOTAL IN xmlguide. . . . "xmlguide.count()

The first part works.
Second part, I wish to filter the xmlguide based on the date. I want to create another array where only the title and desc are added if the date already exist, if it is a new date, add the date, title and desc. This is where I am stuck, not sure how to compare the current date to other dates to see if it already exist and if not to push it to an array along with the title and desc. Any help appreciated.
0 Kudos
4 Replies
NewManLiving
Level 7

Re: Filter Array

Apart from the fact that you can lookup, test for the existence of and/or delete any key in any associative array, a good set of sort routines can be found here: https://github.com/dphang/roku-lib/blob ... tUtils.brs
Threse can be modified to sort anything (I use them extensively myself ) if you wanted to take that approach. But I would first investigate the interface of the AA. I think you may find your answer
My Channels: 2D API Framework Presentation: https://owner.roku.com/add/2M9LCVC
Updated: 11-11-2015 - Completed Keyboard interface
The Joel Channel ( Final Beta )
0 Kudos
Komag
Level 9

Re: Filter Array

Wow, thanks for those sort methods, I was just wanting to upgrade my unstable sort to a stable one without reinventing the wheel!
0 Kudos
btpoole
Level 7

Re: Filter Array

Thank you for pointing me in right direction. I had overlooked lookup and exist.
Thanks again
0 Kudos
TheEndless
Level 7

Re: Filter Array

"btpoole" wrote:
Thank you for pointing me in right direction. I had overlooked lookup and exist.
Thanks again

It's worth nothing that Lookup() and Exists() are often slower than just testing for invalid, presumably due to the reason described here: viewtopic.php?f=34&t=83110&p=476844#p476844
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