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_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "FDataHandler");
while ($data = fread($fp, 4096)) {
if (!xml_parse($xml_parser, $data, feof($fp))) {
die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
rename($XMLPath.$file, $XMLPath.$failpath.$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