You are here:  » xml entries parsed twice ?


xml entries parsed twice ?

Submitted by MarKel on Tue, 2010-08-03 18:17 in

Hello,

i use magicparser to import xlm data (actual car traffic info, updated every 15 minutes) into an mysql database
it seems that xml-entries are parsed TWICE.
i have comment-out the TRUNCATE because i would like to keep the already inserted entries

When i look in the database entries are parsed twice, but when i look at the xml-feed it doesn't show

what's wrong?

regards,

Marcel

<?php
  
require("MagicParser.php");
  
mysql_connect("xxxx","xxxx","xxxx") or die(mysql_error());
  
mysql_select_db("xxxx") or die(mysql_error());
  
$counter 0;
  unset(
$record);
  unset(
$sDate);
  function 
myRecordHandler($record)
  {
  
$sDate date("Y-m-d H:i:s");
  global 
$counter;
     global 
$sql;
  
$counter++;
  
mysql_query($sql);
     
$sql "INSERT INTO xml_fileindex (wegnr, oorzaak, gevolg, van, naar, vansub, naarsub, hectostart, hectoeind, afstand, starttijd, link, trend, trendtekst,datumtijd)
  VALUES (
'"
.mysql_real_escape_string($record["WEGNR"])."',
'"
.mysql_real_escape_string($record["OORZAAK"])."',
'"
.mysql_real_escape_string($record["GEVOLG"])."',
'"
.mysql_real_escape_string($record["VAN"])."',
'"
.mysql_real_escape_string($record["NAAR"])."',
'"
.mysql_real_escape_string($record["VANSUB"])."',
'"
.mysql_real_escape_string($record["NAARSUB"])."',
'"
.mysql_real_escape_string($record["HECTOSTART"])."',
'"
.mysql_real_escape_string($record["HECTOEIND"])."',
'"
.mysql_real_escape_string($record["AFSTAND"])."',
'"
.mysql_real_escape_string($record["STARTTIJD"])."',
'"
.mysql_real_escape_string($record["LINK"])."',
'"
.mysql_real_escape_string($record["TREND"])."',
'"
.mysql_real_escape_string($record["TRENDTEKST"])."',
'"
.mysql_real_escape_string($sDate)."')";
  
mysql_query($sql);
  }
  
// empty table before inserting records
  //$sql = "TRUNCATE xml_fileindex";
  //mysql_query($sql);
  // start parse XML to load new records
MagicParser_parse("{link saved}","myRecordHandler","xml|FILEINDEX/FILEDATA/MELDINGEN/MELDING/");
   print 
"<p>Processed ".$counter." records.</p>";
print 
"<p>Last SQL statement was: ".$sql."</p>";
print 
mysql_error();
echo 
"Data Inserted!";
exit()
?>

Submitted by support on Tue, 2010-08-03 18:44

Hello Marcel,

The XML as I just viewed it definitely only contains 1 MELDINGEN/MELDING/ record, so that looks fine. When you run your script, I see you have this line:

print "<p>Processed ".$counter." records.</p>";

How many records is that saying have been processed? The code for that looks fine.

But I notice that having commented out your TRUNCATE SQL, that you still have at line 14:

  mysql_query($sql);

...this should fail, but whilst testing, it would be best to comment this out as well...

Cheers,
David.

Submitted by MarKel on Tue, 2010-08-03 19:18

David,

not sure which mysql_query($sql) u mean.
you mean the one after the TRUNCATE ?

Submitted by support on Tue, 2010-08-03 19:28

Hi MarKel,

That one is already commented out in the code above - I'm referring to the one at line 14 of that block...

If you're not sure if you're like to email me your script I'll check it out directly for you...

Cheers,
David.