dsg138
asked on
Trouble parsing my XML Feed
Experts,
For the last few years, I've purchased baseball scores and insert them into my database. I wrote a script (with the help from some EE members) to do this automatically every day. This has worked great for 3 years.
Here is the XML of last night's baseball scores: http://www.officepickem.com/rftwscores/xml/BaseballScores10-2-15.xml
As of October 1st, the company where I purchase the feeds from updated their infrastructure and my scripts can no longer read the feeds. I can't figure out what changed.
I'm now getting this error every day: Invalid argument supplied for foreach()
Any ideas?
-dsg
For the last few years, I've purchased baseball scores and insert them into my database. I wrote a script (with the help from some EE members) to do this automatically every day. This has worked great for 3 years.
Here is the XML of last night's baseball scores: http://www.officepickem.com/rftwscores/xml/BaseballScores10-2-15.xml
As of October 1st, the company where I purchase the feeds from updated their infrastructure and my scripts can no longer read the feeds. I can't figure out what changed.
I'm now getting this error every day: Invalid argument supplied for foreach()
Any ideas?
-dsg
$xml = "http://www.officepickem.com/rftwscores/xml/BaseballScores10-2-15.xml";
$obj = SimpleXML_Load_File($xml);
// CREATE AN OBJECT ITERATOR
foreach ($obj->{"sports-content"}->schedule->{"sports-event"} as $game_data)
{
// GET ISO8601-FORMAT DATE ( == MySQL DATETIME )
$date_time = $game_data->{"event-metadata"}["start-date-time"];
// CLEAR ARRAYS FOR CONTEST DATA
$team_name = array();
$team_score = array();
$team_decided = array();
$team_key = array();
// CREATE ANOTHER OBJECT ITERATOR
foreach ($game_data->team as $thing)
{
$team_name[] = $thing->{"team-metadata"}->name["first"] . ' ' . $thing->{"team-metadata"}->name["last"];
$team_key[] = $thing->{"team-metadata"}["team-key"];
$team_score[] = $thing->{"team-stats"}["score"];
$team_decided[] = $thing->{"team-stats"}["event-outcome"];
}
// VISUALIZE RESULTS
echo "<BR>";
echo $team_name[0];
echo " - ";
echo $team_key[0];
echo " - ";
echo $team_score[0];
echo " - ";
echo $team_decided[0];
echo "<P>";
echo $team_name[1];
echo " - ";
echo $team_key[1];
echo " - ";
echo $team_score[1];
echo " - ";
echo $team_decided[1];
echo "<P>";
echo "<p><HR>";
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I think that's the issue.
The older files had one extra root element at the beginning:
<xts:sports-content-set>
</xts:sports-content-set>
The new one doesn't have that.
I made the following change and I think it works now:
From:
foreach ($obj->{"sports-content"}- >schedule- >{"sports- event"} as $game_data)
To:
foreach ($obj->schedule->{"sports- event"} as $game_data)
The older files had one extra root element at the beginning:
<xts:sports-content-set>
</xts:sports-content-set>
The new one doesn't have that.
I made the following change and I think it works now:
From:
foreach ($obj->{"sports-content"}-
To:
foreach ($obj->schedule->{"sports-
ASKER
Thanks!
ASKER
http://www.officepickem.com/rftwscores/xml/Day7.xml
The first line seems to be different, but not sure if it's causing the problem.
<xts:sports-content-set>