If you're generating your xml on demand from a database with php, you can use code to sort the database by year, then month, then day. Generally you'd be feeding that xml during each new screen creation. Or you could download the entire database xml contents to tmp, parse it from there, and have the roku do the sorting and display work. (IMO the second option is a lot more complex, so I chose not to do it that way.)
It is easier to create the source xml by hand, but then you'll have to edit it by hand whenever it changes, and searching becomes difficult.
This would generate your top level categories (Year and Month) and then the feeds for the leaf/month categories send the year and month value to a second index page to have the database return a second xml file to roku with the specific episode data requested.
$sql="SELECT * FROM showdatabase WHERE showname='".$value2."' ORDER BY showdate DESC"; //Do search query based on show name in descending order so the date is always newest first
$res=mysqli_query($con, $sql);
if (mysqli_num_rows($res)==0) //no shows were found in the search
{
$_xml="<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";
$_xml.="<feed>";
$_xml.="<item hdImg=\"http://www.yourserver.com/thumbs/empty.png\">";
$_xml.="<title>Placeholder</title>";
$_xml.="</item>";
$_xml.="</feed>";
echo $_xml;
}
else
{
$mx=0;
$yearcount=0;
$monthcount=0;
while ($info=mysqli_fetch_array($res,MYSQLI_NUM))
{
$ShowName[$mx]=$info[0]; //Show Name
$ShowDate[$mx]=$info[1]; //Date - listed as YYYYMMDD or 20110807 for today
$EpisodeTitle[$mx]=$info[2]; //Title
$EpisodeThumbnail[$mx]=$info[3]; //Thumbnail
$VideoLink[$mx]=$info[4]; //Video Filename
$tempYear=substr($ShowDate[$mx],0,4);
$tempMonth=substr($ShowDate[$mx],0,6);
$found=0;
for($i=0;$i<$yearcount;$i++)
{
if($yearscollect[$i]==$tempYear){$found=1;}
}
if($found==0)
{
$yearscollect[$yearcount]=$tempYear;
$yearcount++;
}
$found=0;
for($i=0;$i<$monthcount;$i++)
{
if($monthscollect[$i]==$tempMonth){$found=1;}
}
if($found==0)
{
$monthscollect[$monthcount]=$tempMonth;
$monthcount++;
}
$mx++;
}
header("Content-Type: application/force-download");
header("Content-Type: text/plain");
header("Content-Transfer-Encoding: binary ");
$_xml='<?xml version="1.0" encoding="UTF-8" ?>'.chr(13);
$_xml.='<categories>'.chr(13);
For ($i=0;$i<$yearcount;$i++)
{
$_xml.="<category title=\"".$yearscollect[$i]."\" hdImg=\"http://www.yourserver.com/thumbs/".$yearscollect[$i]."_HD.png\" sdImg=\"http://www.yourserver.com/thumbs/".$yearscollect[$i]."_SD.png\">".chr(13);
for ($j=0;$j<$monthcount;$j++)
{
$tempoutput=substr($monthscollect[$j],-2);
if($tempoutput=="01"){$tempoutput="January ";}
if($tempoutput=="02"){$tempoutput="February ";}
if($tempoutput=="03"){$tempoutput="March ";}
if($tempoutput=="04"){$tempoutput="April ";}
if($tempoutput=="05"){$tempoutput="May ";}
if($tempoutput=="06"){$tempoutput="June ";}
if($tempoutput=="07"){$tempoutput="July ";}
if($tempoutput=="08"){$tempoutput="August ";}
if($tempoutput=="09"){$tempoutput="September ";}
if($tempoutput=="10"){$tempoutput="October ";}
if($tempoutput=="11"){$tempoutput="November ";}
if($tempoutput=="12"){$tempoutput="December ";}
if(substr($monthscollect[$j],0,4)==$yearscollect[$i]){$_xml.="<categoryLeaf title=\"".$tempoutput.substr($monthscollect[$j],0,4)."\" feed=\"http://www.yourserver.com/index2.html?ind=".$monthscollect[$j]."&show=".$value2."\" />".chr(13);}
}
$_xml.='</category>'.chr(13);
}
$_xml.='</categories>'.chr(13);
echo $_xml;
}
ie, for the second index page the url request would be http://www.yourserver.com/index2.html?ind=201108&show=MyCarsCollection
The index2 page would grab the value of show, and insert it into the sql request like
SELECT * FROM showdatabase WHERE showname="MyCarsCollection" AND ShowDate LIKE "201108%" ORDER BY ShowDate DESC
$sql="SELECT * FROM showdatabase WHERE showname='".$value2."' AND ShowDate LIKE '".$value1."%' ORDER BY ShowDate DESC"; //Do search query
$res=mysqli_query($con, $sql);
if (mysqli_num_rows($res)==0) //no shows
{
$_xml="<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";
$_xml.="<feed>";
$_xml.="<item hdImg=\"http://www.yourserver.com/thumbs/Empty.png\">";
$_xml.="<title>Placeholder</title>";
$_xml.="</item>";
$_xml.="</feed>";
echo $_xml;
}
else
{
$mx=0;
while ($info=mysqli_fetch_array($res,MYSQLI_NUM))
{
$ShowName[$mx]=$info[0]; //Show Name
$ShowDate[$mx]=$info[1]; //Date - listed as YYYYMMDD or 20110807 for today
$EpisodeTitle[$mx]=$info[2]; //Title
$EpisodeThumbnail[$mx]=$info[3]; //Thumbnail
$VideoLink[$mx]=$info[4]; //Video Filename
$mx++;
}
header("Content-Type: application/force-download");
header("Content-Type: text/plain");
header("Content-Transfer-Encoding: binary ");
$_xml="<?xml version=\"1.0\" encoding=\"UTF-8\" ?>".chr(13);
$_xml.="<feed>".chr(13);
For ($i=0;$i<$mx;$i++)
{
$_xml.="<item hdImg=\"http://www.yourserver.com/thumbs/".$EpisodeThumbnail[$i]."\">".chr(13);
$_xml.="<title>".substr($ShowDate[$i],4,2)."/".substr($ShowDate[$i],6,2)."/".substr($ShowDate[$i],0,4)." - ".$EpisodeTitle[$i]."</title>".chr(13);
$_xml.="<media><streamUrl>http://www.yourserver.com/".$VideoLink[$i]."</streamUrl></media>".chr(13);
$_xml.="</item>".chr(13);
}
$_xml.="</feed>".chr(13);
echo $_xml;
}
Naturally, any code can be improved, like having it create multiple streams on the fly, adding other meta data for the episode, adding extra features customized within the database schema, etc etc, but this gives you a good starting point to dynamically interface and generate XML. Any xml you are generating, the channel should be scripted to deal with the format it's being given.