+<?
+// BIFE: Build It FastEr - draft 1
+
+define('TAB', ' ');
+
+$file = "data.xml";
+$depth = array();
+$stack = array();
+
+function startElement($parser, $name, $attrs) {
+ global $depth, $stack;
+ $stack[] = $name;
+ echo str_repeat(TAB, @$depth[$parser]);
+ echo "<$name> ";
+ 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);
+
+?>