From: Leandro Lucarella Date: Sat, 17 May 2003 04:28:50 +0000 (+0000) Subject: BIFE draft 1. Implements a generic XML parser. X-Git-Tag: svn_import~61 X-Git-Url: https://git.llucax.com/software/bife/bife-all.git/commitdiff_plain/4448c01b82a3d4606d3398b3483d7c1b699a3aa9?ds=inline BIFE draft 1. Implements a generic XML parser. --- 4448c01b82a3d4606d3398b3483d7c1b699a3aa9 diff --git a/data.xml b/data.xml new file mode 100644 index 0000000..06782ae --- /dev/null +++ b/data.xml @@ -0,0 +1,19 @@ + + Titulo +

+ Hola, gente, como estan todos? Esta es solo la primera prueba de + BIFE, un cuasi-framework inspirado en BIF. +

+ Subtitulo + + Item loco. + Otro item loco. + + + Album de fotos + + + Este es mi perfil + +
diff --git a/index.php b/index.php new file mode 100644 index 0000000..ffb2810 --- /dev/null +++ b/index.php @@ -0,0 +1,61 @@ + "; + foreach ($attrs as $attr => $val) { + echo "$attr: '$val' "; + } + echo "\n"; + @$depth[$parser]++; +} + +function endElement($parser, $name) { + global $depth, $stack; + array_pop($stack); + $depth[$parser]--; +} + +function characterData($parser, $data) { + static $last = ''; + global $depth, $stack; + $current = join('/', $stack); + $data = trim($data); + if ($data) { + echo str_repeat(TAB, @$depth[$parser]); + if ($current !== $last) { + $last = $current; + echo "En $current: "; + } else { + echo " "; + } + echo "'$data'\n"; + } +} + +$xml_parser = xml_parser_create(); +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\n"); +} + +while ($data = fread($fp, 4096)) { + if (!xml_parse($xml_parser, $data, feof($fp))) { + die(sprintf("XML error: %s at line %d\n", + xml_error_string(xml_get_error_code($xml_parser)), + xml_get_current_line_number($xml_parser))); + } +} +xml_parser_free($xml_parser); + +?>