Topic awaiting preservation: Problem with parsing remote xml files |
|
---|---|
Author | Thread |
Paranoid (IV) Inmate From: Rouen, France |
posted 03-26-2006 17:14
Hi everybody, code: Array ( [0] => Array ( [name] => Armania [race] => 8 [class] => 7 [level] => 8 [map] => 1 [zone] => 14 [ping] => 5 [ip] => 62.147.129.134 ) [1] => Array ( [name] => Nanami [race] => 5 [class] => 8 [level] => 11 [map] => 0 [zone] => 85 [ping] => 28 [ip] => 83.112.234.13 ) [2] => Array ( [name] => GlenoXx [race] => 4 [class] => 11 [level] => 21 [map] => 1 [zone] => 17 [ping] => 9 --- note : missing a tag here --- ) )
code: function run_xml_parser ($xml_file, $start_tag_function, $end_tag_function, $data_function) { $xp = xml_parser_create(); xml_set_element_handler ($xp, $start_tag_function, $end_tag_function); xml_set_character_data_handler ($xp, $data_function); xml_parser_set_option ($xp, XML_OPTION_CASE_FOLDING, FALSE); xml_parser_set_option ($xp, XML_OPTION_SKIP_WHITE, TRUE); $file = fopen ($xml_file, "rb"); while ($xml = fread ($file, 4096)) { if (!xml_parse ($xp, $xml, feof ($file))) { die("XML parser error: " . xml_error_string (xml_get_error_code ($xp))); } } xml_parser_free ($xp); }
|
Maniac (V) Mad Scientist with Finglongers From: Germany |
posted 03-26-2006 17:51
yeah.. you're not concatinating the data you read, placing half of an xml string probalby right in the middle of <tags> in there... code: $file = fopen ($xml_file, "rb"); $xml = ''; while ($buffer = fread ($file, 4096)) { $xml .= $buffer; } if (!xml_parse ($xp, $xml, feof ($file))) { die("XML parser error: " . xml_error_string (xml_get_error_code ($xp))); }
|
Paranoid (IV) Inmate From: Rouen, France |
posted 03-26-2006 21:19
Ohhh thanks TP for pointing that out |
Maniac (V) Mad Scientist From: 100101010011 <-- right about here |
posted 03-26-2006 21:37
I believe TP's code won't parse anything more than the 4069 bytes of a file. |
Paranoid (IV) Inmate From: Rouen, France |
posted 03-26-2006 23:28
Well, using that piece of code works the same... I still get partial xml files. code: $xml = fread ( $handle, filesize ($xml_file) );
code: $xml = file_get_contents($xml_file);
|
Maniac (V) Mad Scientist with Finglongers From: Germany |
posted 03-27-2006 06:47
yeah... http requests can be like that. |
Paranoid (IV) Inmate From: Rouen, France |
posted 03-29-2006 00:31
I tried that as a last resort : code: $max_loops = 5; $loops = 0; while ( (strpos($xml, "</stats>") === false) && ($loops < $max_loops)) { $handle = fopen ($xml_file, "rb"); $xml = ''; while ($buffer = fread ($handle, 4096)) $xml .= $buffer; $loops++; fclose($handle); }
|
Obsessive-Compulsive (I) Inmate From: |
posted 05-01-2006 11:57
Looks like I'm late, I thought maybe the file is being written to while you're reading it? Can you lock files on another server for reading? |