XML errors after looping through many files
| From: | Lewis Bergman | Date: | Thu, 12 Oct 2000 22:14:02 +0000 |
| Subject: | XML errors after looping through many files | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-19915@lists.php.net to get a copy of this message | ||
I have been kicking this from different directions and have reached a sticking
point.
The part of the code that I think matters is at the end of the message.
I am looping through about two hundred plus xml files.
After about 40 of them I get different XML errors spit out at me depending on
what happens to be the last tag processed. All XML files have been validated
and are of identical format. It seemed that it might be a time issue (takes a
while) so i increased the timeout and it still occurs well within this. Maybe
memory, no, that wasn't it either, increased it to no effect. At this point I
would be happy if I could just intercept the error and continue the process. I
don't believe it would be succesful if I could do it which I can't find a way
to in the XML functions anyway.
It seems to be a resource issue but none that I am familiar with. If anyone has
any clues they would be much appreciated.
while($myrow = mysql_fetch_array($result, MYSQL_ASSOC)) {
// declare the character set - iso-8859-1 is the default
$type = 'iso-8859-1';
// create our parser
$xml_parser = xml_parser_create($type);
// set some parser options
xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, 1);
xml_parser_set_option($xml_parser, XML_OPTION_TARGET_ENCODING, 'iso-8859-1');
// this tells PHP what functions to call when it finds an element
// these funcitons also handle the element's attributes
xml_set_element_handler($xml_parser, 'startElement','endElement');
// this tells PHP what function to use on the character data
xml_set_character_data_handler($xml_parser, 'characterData');
// assign the url to a var
$xml_file = $myrow["file_source"];
echo "current file processing ==> ". $xml_file."<BR>\n";
// open the file
if (!($fp = fopen($xml_file, "r"))) {
die(sprintf("Could not open %s for parsing!<BR>\n", $xml_file));
}
// loop through the file and parse
while ($data = fread($fp, 1000000)) {
if (!xml_parse($xml_parser, $data, feof($fp))) {
die(sprintf( "XML error: %s at line %d\n\n",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
xml_parser_free($xml_parser);
}
}
--
Lewis Bergman
Texas Communications
4309 Maple St.
Abilene, TX 79602
915-695-6962