Hi people!
I’m having a little trouble getting an XML file to load & display correctly using PHP. I’ve been able to do it with all my other XML Reports so far, but this one is structured a little differently to how I’m used to so I’m not sure how to go about calling up the relevant objects within the XML file.
The full URL of the XML File is:
Please note, the two parts in red (the date). I am using the below PHP code to automatically update this URL and load the current XML File for today’s date.
$today = date ('m/d/Y');
$file = 'http://www.zdki.us/taReportsw/DailyIntros.aspx?ReportType=AstroWeather&DateFrom=' . urlencode($today) . '&DateTo=' . urlencode($today) . '&ReportFormat=XML&NewsFlash=&AccountID=Neosis&AppID=CDS&MemberID=1234567890&V=2';
$xml = simplexml_load_file($file);
That part, I’m comfortable with - I’ve used the same method to connect to all of my remote XML Files for daily content and it works perfectly… The next part is where I am trying to tell the page which objects from the XML file I want to display and that is what I’m having trouble with.
The Full XML structure is as follows:
<dailyintros>
<date-20110318>
<astroweather>
<astroweathershort>
Some Content Here
</astroweathershort>
<astroweatherlong>
Some More content Here
</astroweatherlong>
</astroweather>
</date-20110318>
</dailyintros>
I want to display just the part where it says “Some more content here” - so that’s the part wrapped in the “astroweatherlong” tags.
The problem I am having seems to have something to do with the “date-20110318” tag, which I assume is a parent to the tag that I am actually trying to fetch. It seems that because it has the word “date” in it, I need to call it differently somehow. Also, because it needs to be the “current” date, I need that to change like the date in the URL does.
I’ve tried the following variations but neither of them are working:
$reportdate= date ('Ymd');
<?php echo $xml->dailyintros->date-$reportdate->astroweather->astroweatherlong; ?>
<?php echo $xml->dailyintros->'date-$reportdate'->astroweather->astroweatherlong; ?>
<?php echo $xml->dailyintros->'date'-$reportdate->astroweather->astroweatherlong; ?>
I even tried it using the actual tag that is shown above (the full date-20110318) but that didn’t work either. It has to be something to do with the word “date” with that being a PHP function itself…
Can someone please tell me how to call this section of the XML file and make it so that it always calls “today’s” one?
Thanks,