epsilon624 Posted October 8, 2007 Share Posted October 8, 2007 Well I have two problems. I am trying to read in a few XML's from a couple different poker sites and then trying to parse them to display the latest tournaments that are going to be happening. Is there any way I can just read in the file from http://tourneys.absolutepoker.com:8055/TourSchedule.xml to parse it. Right now I can only figure out how to copy and paste the file onto my server and then open it from there. Next, I am having problems parsing it. I am putting each attribute into a two dimensional array when I am parsing it, but I cannot access thi sarray outside of the function. I have the same echo statement inside the function and outside and it only prints it when it is inside the function. Here is the code that I have... <? define ('LT', '<'); define ('GT', '>'); function handle_open_element ($parser, $element, $attributes) { $element = strtolower($element); switch ($element) { case 'a': $i = 1; foreach ($attributes as $key => $value) { $key = strtolower($key); echo $key; $absolute[$i][$key] = $value; echo $absolute[$i][$key]; echo '<br />' . $absolute[1][tournamentid]; echo '<br />' . $i; echo '<br /><br />'; $i++; } echo $absolute[1][tournamentid]; break; case 'tournament': echo ' ' . LT . $element; /* foreach ($attributes as $key => $value) { echo ' ' . strtolower($key) . '="' . $value . '"'; } */ echo GT . '<br />'; break; default: break; } } function handle_close_element($parser, $element) { } function handle_character_data ($parser, $cdata) { } $parser = xml_parser_create(); xml_set_element_handler ($parser, 'handle_open_element', 'handle_close_element'); xml_set_character_data_handler($parser, 'handle_character_data'); $file = 'http://www.pacificpoker.com/PokerTourInfo'; $fp = @fopen ($file, 'r') or die ("Cound not open a file called '$file'"); while ($data = fread ($fp, filesize($file))) { xml_parse ($parser, $data, feof($fp)); } echo '<br /><br />'; //echo $absolute[1][tournamentid]; xml_parser_free($p); ?> Quote Link to comment Share on other sites More sharing options...
TomKrush Posted October 8, 2007 Share Posted October 8, 2007 It seems you can retrieve the file. To parse it I'd recommend DomDocument. You can find more documentation of it on http://docs.php.net/dom Using xml_parser_create is much dirtier to work with. The only disadvantage of DomDocument is you need strict xml. <?php $document = new DomDocument(); $document -> loadXML($string); $element = $document -> getElementById("someID"); ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.