I think this is a step in the right direction. I'm learning a lot about this by trying to work this out.
It would be nice if we could just pick out the month by using it's attribute instead of looping through every month. I haven't figured out how to do that yet. Hopefully someone who is good with simpleXML will help us out.
event.xml
Code:
<?xml version="1.0" encoding="ISO88591" ?>
<calendar ver="2.0">
<yar yeartag="2009">
<mn m="1">
<dy d="1">
<shorttext>Day 1 Short</shorttext>
<link>Day 1 LINK</link>
<longtext>Day 1 Long</longtext>
</dy>
<dy d="2">
<shorttext />
<link />
<longtext />
</dy>
<dy d="3">
<shorttext />
<link />
<longtext />
</dy>
<dy d="4">
<shorttext />
<link />
<longtext />
</dy>
<dy d="5">
<shorttext>Dancing and Wii Tourney</shorttext>
<link>Click here for Dancing</link>
<longtext>Long Wii text and Dancing</longtext>
</dy>
<dy d="6">
<shorttext />
<link />
<longtext />
</dy>
<dy d="7">
<shorttext />
<link />
<longtext />
</dy>
</mn>
<mn m="2">
<dy d="1">
<shorttext />
<link />
<longtext />
</dy>
<dy d="2">
<shorttext />
<link />
<longtext />
</dy>
<dy d="3">
<shorttext>Month 2 day 3 short</shorttext>
<link>LINK LINK</link>
<longtext>Long text for day 2/3</longtext>
</dy>
<dy d="4">
<shorttext />
<link />
<longtext />
</dy>
<dy d="5">
<shorttext />
<link />
<longtext />
</dy>
<dy d="6">
<shorttext />
<link />
<longtext />
</dy>
<dy d="7">
<shorttext />
<link />
<longtext />
</dy>
</mn>
<mn m="3">
<dy d="1">
<shorttext />
<link />
<longtext />
</dy>
<dy d="2">
<shorttext />
<link />
<longtext />
</dy>
<dy d="3">
<shorttext>Month 3 day 3 short</shorttext>
<link>LINK LINK</link>
<longtext>Long text for day 3/3</longtext>
</dy>
<dy d="4">
<shorttext />
<link />
<longtext />
</dy>
<dy d="5">
<shorttext />
<link />
<longtext />
</dy>
<dy d="6">
<shorttext />
<link />
<longtext />
</dy>
<dy d="7">
<shorttext />
<link />
<longtext />
</dy>
</mn>
<mn m="4">
<dy d="1">
<shorttext />
<link />
<longtext />
</dy>
<dy d="2">
<shorttext />
<link />
<longtext />
</dy>
<dy d="3">
<shorttext>Month 4 day 3 short</shorttext>
<link>LINK LINK</link>
<longtext>Long text for day 4/3</longtext>
</dy>
<dy d="4">
<shorttext />
<link />
<longtext />
</dy>
<dy d="5">
<shorttext />
<link />
<longtext />
</dy>
<dy d="6">
<shorttext />
<link />
<longtext />
</dy>
<dy d="7">
<shorttext />
<link />
<longtext />
</dy>
</mn>
</yar>
</calendar>
Your php file :
PHP Code:
<?php
$xml = simplexml_load_file('event.xml');
$currentYear = date('Y');
$currentMonth = date('n');
$years = $xml->yar;
foreach ( $years as $year ) {
if ( $year->attributes()->yeartag == $currentYear ) {
$months = $year->mn;
foreach ( $months as $month ) {
if ( $month->attributes()->m == $currentMonth ) {
$days = $month->children(); // All the days
foreach ( $days as $day ) {
// I guess the calendar would get output here:
echo $month->attributes()->m . '/' . $day->attributes()->d . '<br />';
echo !empty( $day->shorttext ) ? $day->shorttext . '<br />' : '';
echo !empty( $day->link ) ? $day->link . '<br />' : '';
echo !empty( $day->longtext ) ? $day->longtext . '<br />' : '';
}
}
}
}
}
?>
I really am not happy with all the nested foreach loops. Being able to select elements based on their attributes would be great. I'll keep trying to figure that out.
Bookmarks