'',
'INFO' => '',
'FOLDER' => '',
'TITLE' => '',
'BOOKMARK' => '',
'DESC' => ''
);
$close_tags = array(
'XBEL' => '',
'INFO' => '',
'FOLDER' => '',
'TITLE' => '',
'BOOKMARK' => '',
'DESC' => ''
);
function xbel() {
echo "
";
echo '';
if (!$file) {
$file = "http://www.alessandrobuzzi.it/xbel.xml";
}
$xml_parser = xml_parser_create($type);
xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, true);
xml_parser_set_option($xml_parser, XML_OPTION_TARGET_ENCODING, 'UTF-8');
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
if (!($fp = fopen($file, "r"))) {
die("could not open XML input");
}
while ($data = fread($fp, 4096)) {
$data = ereg_replace('&', '&', $data);
if (!xml_parse($xml_parser, $data, feof($fp))) {
die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
}
xml_parser_free($xml_parser);
}
function openTable($id,$title){
echo("
");
echo "";
}
function closeTable(){
echo "
";
}
function addDoc($url,$title){
echo "
";
}
function startElement($parser, $name, $attrs) {
global $open_tags, $current_tag, $depth, $tb, $hs, $na;
$current_tag = $name;
$hs++;
switch($name) {
case 'BOOKMARK':
$tb['url'] = $attrs['HREF'];
break;
default:
break;
}
array_push($depth, $name);
}
function endElement($parser, $name) {
global $close_tags, $tb, $current_tag, $depth, $hs;
switch($name) {
case 'FOLDER':
closeTable();
break;
case 'BOOKMARK':
$tb = '';
break;
default:
break;
}
array_pop($depth);
$hs--;
}
function characterData($parser, $data) {
global $current_tag, $tb, $catID, $depth, $hs, $nb,$tcounter;
switch($current_tag) {
case 'BOOKMARK':
$tb['bookmark'] .= $data;
$current_tag = '';
break;
case 'TITLE':
$tpp = array_pop($depth);
if (end($depth) == 'FOLDER') {
openTable("table" . $tcounter++,$data);
$tpp2 = array_pop($depth);
array_push($depth, $tpp2);
} else {
$tb['title'] .= $data;
addDoc($tb['url'],$tb['title']);
$current_tag = '';
}
array_push($depth, $tpp);
break;
case 'DESC':
$tpp = array_pop($depth);
if (end($depth) == 'BOOKMARK') {
$tb['desc'] .= $data;
$current_tag = '';
}
array_push($depth, $tpp);
break;
case 'URL':
$tb['url'] .= $data;
$current_tag = '';
break;
default:
break;
}
}