OZONE Asylum
Forums
Server-Side Scripting - Oh my!
Problem with parsing remote xml files
This page's ID:
27694
Search
QuickChanges
Forums
FAQ
Archives
Register
Edit Post
Who can edit a post?
The poster and administrators may edit a post. The poster can only edit it for a short while after the initial post.
Your User Name:
Your Password:
Login Options:
Remember Me On This Computer
Your Text:
Insert Slimies »
Insert UBB Code »
Close
Last Tag
|
All Tags
UBB Help
Hi everybody, Ok let me explain the situation. What I want to do is to parse several remote xml files with php, process the data and then output it with a nice layout. To do that, I set up a xml parser both from php.net examples and a parser Emp wrote some time ago and adjusted it to suit my needs. It is running fine now and the data is processed correctly, I have no problems with this side. What is worrying me is that 3 times out of 4, I get only a part of the xml file. For example, when I to process a file like [url=http://moon.ombre.free.fr/ozone/stats.xml]that[/url], what I get is almost always the three first arrays with a missing tag at the end : [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] Typically, the files are located on remote user computers, so I have to access them with urls like http://server:port/stat.xml. My first thought was that the remote server was closing the connection and that it prevented my script to parse the whole file. But since the script manages to parse the whole file some times, I don't think this is the real reason. Here's the function I am using : [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); } [/code] Anyone knows what I am doing wrong ? ---- If wishes were fishes, we'd all cast nets. [small](Edited by [url=http://www.ozoneasylum.com/user/2913]Moon Shadow[/url] on 03-26-2006 17:18)[/small]
Loading...
Options:
Enable Slimies
Enable Linkwords
« Backwards
—
Onwards »
Maximum Security
OZONE
DHTML/Javascript
Server-Side Scripting - Oh my!
CSS - DOM - XHTML - XML - XSL - XSLT
Stupid Basic HTML
Visual Therapy
Photoshop
Photoshop Pong, Anyone?
***WARNING*** BIG SIG APPROACHING
Photography
3D Modelling & Rendering
Multimedia/Animation
Print Graphics
Holding Pens
Philosophy and other Silliness
Outpatient Counseling
Site reviews!
Mad Scientists' Laboratory
Getting to know the Grail