2 // BIFE: Build It FastEr - draft 1
10 function startElement($parser, $name, $attrs) {
11 global $depth, $stack;
13 echo str_repeat(TAB, @$depth[$parser]);
15 foreach ($attrs as $attr => $val) {
16 echo "$attr: '$val' ";
22 function endElement($parser, $name) {
23 global $depth, $stack;
28 function characterData($parser, $data) {
30 global $depth, $stack;
31 $current = join('/', $stack);
34 echo str_repeat(TAB, @$depth[$parser]);
35 if ($current !== $last) {
45 $xml_parser = xml_parser_create();
46 xml_set_element_handler($xml_parser, "startElement", "endElement");
47 xml_set_character_data_handler($xml_parser, "characterData");
48 if (!($fp = @fopen($file, "r"))) {
49 die("could not open XML input\n");
52 while ($data = fread($fp, 4096)) {
53 if (!xml_parse($xml_parser, $data, feof($fp))) {
54 die(sprintf("XML error: %s at line %d\n",
55 xml_error_string(xml_get_error_code($xml_parser)),
56 xml_get_current_line_number($xml_parser)));
59 xml_parser_free($xml_parser);