1#!tclsh 2 3load ../../unix/libtdom0.7.5.so 4load ./libexample1.0.0.so 5 6set counter1 0 7set counter2 0 8 9proc eh1 {args} { 10 global counter1 11 12 incr counter1 13} 14proc eh2 {args} { 15 global counter2 16 17 incr counter2 18} 19 20set parser [expat] 21$parser configure -elementstartcommand eh1 \ 22 -handlerset doMore \ 23 -elementstartcommand eh2 24example $parser enable 25tdom $parser enable 26 27set fd [open ../../tests/data/books.xml] 28$parser parse [read $fd] 29 30puts "First tcl element start handler has counted the elements" 31puts "(and 42 isn't a bad answer at all)" 32puts "counter1: $counter1" 33puts "\nSecond tcl element start handler has also counted the elements" 34puts "(and should therefore report the same reasonable result)" 35puts "counter2: $counter2" 36 37puts "\nthe example C level handler set also counts the elements..." 38puts "(and should maybe do some validation, instead of this ridiculous counting..)" 39puts "example result: [example $parser getresult]" 40set doc [tdom $parser getdoc] 41 42set root [$doc documentElement] 43puts "\n... but the second C level handler has done some serious work" 44puts "DOM result tree root: [$root nodeName]" 45 46puts "\nOK, reset the parser..." 47$parser reset 48puts "\nSome senseless fiddling with the result encoding" 49puts [tdom $parser setResultEncoding] 50puts [tdom $parser setResultEncoding iso8859-1] 51puts [tdom $parser setResultEncoding] 52 53puts "\nRemove the tdom handler set and parse again" 54tdom $parser remove 55 56seek $fd 0 start 57$parser parse [read $fd] 58 59puts "\nthe both tcl counters count further, thats OK" 60puts "counter1: $counter1" 61puts "counter2: $counter2" 62puts "\nthe example counter is reseted because of the parser reset" 63puts "example result: [example $parser getresult]" 64puts "\nthe DOM tree created in the first parser run is still alive" 65puts [$root childNodes] 66 67 68