I've to manage quite very large XML files. I tough it was an SQL error, but
I've figured out the problem is somewhere else.
I've a big structure, with lot of datas and pictures encoded in every XML
files. Sometimes, I've error, and the script crashes.
Here is the code:
$xml_parser = xml_parser_crea te();
xml_set_element _handler($xml_p arser, "startEleme nt", "endElement ");
xml_set_charact er_data_handler ($xml_parser, "FDataHandler") ;
while ($data = fread($fp, 4096)) {
if (!xml_parse($xm l_parser, $data, feof($fp))) {
die(sprintf("XM L error: %s at line %d",
xml_error_strin g(xml_get_error _code($xml_pars er)),
xml_get_current _line_number($x ml_parser)));
rename($XMLPath .$file, $XMLPath.$failp ath.$file); //move file in error
path
$OK = false;
}
}
fclose($fp);
xml_parser_free ($xml_parser);
Now, this part of the code takes 4096 bytes and parse datas:
<datastart>
<data1>20040101 </data1>
<data2>20040220 </data2>
<data3>20040810 </data3>
</datastart>
Now, if the 4096 bytes are in the middle of the file, I get big problems. In
my case, the data2 is cutted somewhere in the middle
The script should only work when the </datastart> is reached, isn'it ??? but
how to do so ? The actual file is 5MB large, with lot of pictures in it.
Bob
I've figured out the problem is somewhere else.
I've a big structure, with lot of datas and pictures encoded in every XML
files. Sometimes, I've error, and the script crashes.
Here is the code:
$xml_parser = xml_parser_crea te();
xml_set_element _handler($xml_p arser, "startEleme nt", "endElement ");
xml_set_charact er_data_handler ($xml_parser, "FDataHandler") ;
while ($data = fread($fp, 4096)) {
if (!xml_parse($xm l_parser, $data, feof($fp))) {
die(sprintf("XM L error: %s at line %d",
xml_error_strin g(xml_get_error _code($xml_pars er)),
xml_get_current _line_number($x ml_parser)));
rename($XMLPath .$file, $XMLPath.$failp ath.$file); //move file in error
path
$OK = false;
}
}
fclose($fp);
xml_parser_free ($xml_parser);
Now, this part of the code takes 4096 bytes and parse datas:
<datastart>
<data1>20040101 </data1>
<data2>20040220 </data2>
<data3>20040810 </data3>
</datastart>
Now, if the 4096 bytes are in the middle of the file, I get big problems. In
my case, the data2 is cutted somewhere in the middle
The script should only work when the </datastart> is reached, isn'it ??? but
how to do so ? The actual file is 5MB large, with lot of pictures in it.
Bob
Comment