load($path_xml)) //if not loaded, then print error {print " XML $path_xml not loaded into DOM Document
";} $sxe = simplexml_load_file($path_xml); //load as simpleXML using the same variable $path_xml as first initialised above foreach($sxe->adestination as $oneDest) //put adestination into a variable so we can loop and access easily { $varDest = $oneDest->destinationname; //use the variable $oneDest to access destinationname, put value into variable $varDest $varCoun = $oneDest->countryname; //use the variable $oneDest to access countryname, put value into $varCoun //INNER LOOP TO ACHIEVE OUTPUT OF EACH ACTIVITY & INSERT CORRECT DATA TO TABLE foreach($oneDest->activity as $oneAct) //INNER LOOP , creating oneAct from $oneDest which contains 'adestination' { $act = $oneAct; //loop thru the activities for that particular destination $varActi = $act; //and put the activity into $varActi at each loop $query = "INSERT INTO COUNTRY VALUES('$varDest', '$varCoun', '$varActi')"; //insert from outer loop ($varDest & $varCoun) and inner loop ($varActi) if(!sqlite_query($dbhandle, $query)) { echo "Could not insert table row"; } //error management } } //SELECT THE NEW DATA IN THE TABLE $query = sqlite_query($dbhandle, 'SELECT * FROM COUNTRY'); //SELECT ALL, result set goes into variable $query $result = sqlite_fetch_all($query, SQLITE_ASSOC); //$result holds an array of records/fields with all fields referenced by name (or SQLITE_NUM for col num eg 0,1..) //PRINT IN TABLE FORMAT print ""; print ""; print ""; //print field headings foreach ($result as $arow) { //for each array in $result, put into $arow echo '' . ''; } print "
DestinationnameCountrynameActivity
' . $arow['destinationname'] . ' ' . $arow['countryname'] . '' . $arow['activity'] . '
"; //DISPLAY THE ARRAY TO CHECK THE DATA EXTRACTED FROM THE TABLE IS CORRECT print "
";
  print_r( $result);  
  print "
"; sqlite_close($dbhandle); ?>