Maybe this is just my poor coding, but something seems to be very wrong with the built in XML parser..
To start off - I'm parsing up
http://www.fark.com/XML.xml
Below is the code I'm using:
<?php
$fp = fopen('XML.xml', 'r');
$link = -1;
$cur_tag = '';
$xml = xml_parser_create();
xml_set_element_handler($xml, 'start', 'stop');
xml_set_character_data_handler($xml, 'data');
while($thefile = fread($fp, 1024)){
if(!xml_parse($xml, $thefile, feof($fp))){
break;
}
}
function start($parser, $element, $attribs){
global $link, $cur_tag;
if($element == 'LINK'){
$link++;
}
if($element=='LINK' && $link==0){
echo "<br>---------------<br>";
}
$cur_tag = $element;
}
function stop($parser, $element){
global $link, $cur_tag;
if($element == 'LINK'){
$link--;
}
$cur_tag = '';
}
function data($parser, $data){
global $link, $cur_tag;
if($cur_tag=='ID' || $cur_tag=='CATEGORY_ICON' || $cur_tag=='SOURCE' || $cur_tag=='DESCRIPTION' || $cur_tag=='DATE' || ($cur_tag=='LINK' && $link==1)){
if($cur_tag=='CATEGORY_ICON'){
$beggining = strrpos($data, 'ALT="');
$data = substr($data, $beggining+6);
}
echo "$cur_tag - $data<br>";
}
}
fclose($fp);
xml_parser_free($xml);
?>
and this is the output I get.
---------------
ID - 266865
LINK - http://go.fark.com/cgi/fark/go.pl?location=http://www.beverage-digest.com/editorial/headline.html&IDLink=266865
SOURCE - (Some Sub)
DESCRIPTION - Beverage Digest: The inside scoop on the Cola Wars
CATEGORY_ICON - Interesting
CATEGORY_ICON -
DATE - August 9, 2002
ID - 266844
LINK - http://go.fark.com/cgi/fark/go.pl?location=http://www.wnbc.com/sh/employment/stories/employment-160354220020809-090822.html&IDLink=266844
SOURCE - (wnbc.com)
DESCRIPTION - Florida Union Accused of Using Voodoo
CATEGORY_ICON - Strange
CATEGORY_ICON -
DATE - August 9, 2002
================
Now maybe I'm missing something obvious - but why on earth would it go back do category_icon again?