Hello everyone,
I need some help with a PHP screen scrape to XML. I already have the scrape working and I am taking the data and making a new DOM doc and exporting the data as XML.
The data is a schedule and the way I am doing it now makes a node for each game.
What I am having some trouble doing is separating each game by the month it is in. Below is a sample of the XML structure...
<Schedule>
<Game>
<Date>October 2009</Date>
<Visitor><Visitor/>
<Home><Home/>
<Time><Time/>
<Results><Results/>
</Game>
<Game>
<Date>Fri Oct 3</Date>
<Visitor>Visiting Team<Visitor/>
<Home>Home Team<Home/>
<Time>TheTime<Time/>
<Results><Results/>
</Game>
</Schedule>
Notice how the the one game node has the month October 2009 in it....this is what I would like...
<Schedule>
<Month>October 2009
<Game>
<Date>Fri Oct 3</Date>
<Visitor>Visiting Team<Visitor/>
<Home>Home Team<Home/>
<Time>TheTime<Time/>
<Results><Results/>
</Game>
</Month>
</Schedule>
Here is my code....I have tried using if statements to analyze the month and if it is to append a new node and put the game node inside the month. Just need some direction to open to all comments! Thanks!
$schedule = $doc->createElement( "Schedule" );
$doc->appendChild( $schedule );
foreach( $regular_season as $reg_season )
{
$game = $doc->createElement( "Game" );
$date = $doc->createElement( "Date" );
$date->appendChild(
$doc->createTextNode( $reg_season[0])
);
$game->appendChild( $date );
$visitor = $doc->createElement( "Visitor" );
$visitor->appendChild(
$doc->createTextNode( $reg_season[1] )
);
$game->appendChild( $visitor );
$home = $doc->createElement( "Home" );
$home->appendChild(
$doc->createTextNode( $reg_season[2] )
);
$game->appendChild( $home );
$time = $doc->createElement( "Time" );
$time->appendChild(
$doc->createTextNode( $reg_season[3] )
);
$game->appendChild( $time );
$networkResults = $doc->createElement( "Results" );
$networkResults->appendChild(
$doc->createTextNode( $reg_season[4] )
);
$game->appendChild( $networkResults );
$schedule->appendChild( $game );
}