Forum Discussion

btpoole's avatar
btpoole
Channel Surfer
10 years ago

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.

4 Replies

  • 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
  • Wow, thanks for those sort methods, I was just wanting to upgrade my unstable sort to a stable one without reinventing the wheel!
  • btpoole's avatar
    btpoole
    Channel Surfer
    Thank you for pointing me in right direction. I had overlooked lookup and exist.
    Thanks again
  • "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