Hello,
I have recently posted a few questions about exporting XML into PHP into MySql.
I have created my PHP file which exports my XML into MySql which works great, if, i have only 1 XML in the XML file. The files will come daily with over 200 XML.
I have attached a snipit of my code below:
$xmlDoc = new DOMDocument();
$xmlDoc->load( 'cdocument-2012-03-05.xml' );
$thisnodeone = $xmlDoc->getElementsByTagName('ConferenceData');
foreach ($thisnodeone as $nodes )
{
///// My-ConferenceData //////
echo "<strong>ConferenceData</strong><br /><br />";
$itemnodes = $xmlDoc->getElementsByTagName( "ConferenceData" );
$nodes = $itemnodes->item(0)->getElementsByTagName( "Event" );
for ( $i = 0; $i < $nodes->length; $i++ )
{
$valueConferenceDataEvent = $nodes->item( $i++ )->getAttribute('value');
echo "Event - $valueConferenceDataEvent<br /><br />";
}
///// My-Basic-Information //////
echo "<br /><br /><br /><strong>Basic-Information</strong><br /><br />";
$itemnodes = $xmlDoc->getElementsByTagName( "Basic-Information" );
$nodes = $itemnodes->item(0)->getElementsByTagName( "Conference-ID" );
for ( $i = 0; $i < $nodes->length; $i++ )
{
$valueBasicInformationConferenceID = $nodes->item( $i++ )->getAttribute('value');
echo "Conference-ID - $valueBasicInformationConferenceID<br /><br />";
}
$sql = "insert into `XXXXXX` (`ConferenceID`) values ('$valueBasicInformationConferenceID')";
$perform_insert = mysql_query($sql) or die("<b>Data could not be entered</b>.\n<br />Query: " . $query . "<br />\nError: (" . mysql_errno() . ") " . mysql_error())
}
please note that near to the top of this i have tried to separate the XML's to parse through and insert as new table rows in MySql with the ID being 'ConferenceID'.
My XML Would have over 200 XML and a snipit again i have put below:
<conferences>
<ConferenceData>
<Event value="myevent" />
<Scheduling-Data>
<Conference>
<Basic-Information>
<Conference-ID value="myconferenceid" />
</Basic-Information>
</Conference>
</Scheduling-Data>
</ConferenceData>
</conferences>
If anyone could help me with this i would be extremely grateful.
Many Thanks