1#!/bin/sh 2#\ 3exec tclsh8.1 "$0" "$@" 4 5# This tests the function of the break facility 6 7lappend auto_path [file dirname [info script]] 8package require expat 9 10proc element {tag name {attrs {}}} { 11 array set at $attrs 12 if {[info exists at(class)]} { 13 switch $at(class) { 14 continue { 15 return -code continue 16 } 17 break { 18 return -code break 19 } 20 error { 21 return -code error "error condition in XML" 22 } 23 } 24 } 25} 26proc pi {name args} { 27 if {$name eq "break"} { 28 return -code break 29 } 30} 31proc pcdata pcdata { 32 if {[string length [string trim $pcdata]]} { 33 puts $pcdata 34 } 35} 36 37set data(test1) {<?xml version="1.0"?> 38<!DOCTYPE Test SYSTEM "test.dtd"> 39<Test> 40<Element>Should see this data</Element> 41<Element class="break">Should not see this data</Element> 42<Element>Should not see this data</Element> 43</Test>} 44set data(test2) {<?xml version="1.0"?> 45<!DOCTYPE Test SYSTEM "test.dtd"> 46<Test> 47<Element>Should see this data</Element> 48<Element>Should see this data 49 <Element class="break">Should not see this data</Element> 50</Element> 51<Element>Should not see this data</Element> 52</Test>} 53set data(test3) {<?xml version="1.0"?> 54<!DOCTYPE Test SYSTEM "test.dtd"> 55<Test> 56<Element>Should see this data</Element> 57<Element>Should see this data</Element> 58<?break?> 59<Element>Should not see this data</Element> 60</Test>} 61 62set parser [expat xmlparser \ 63 -elementstartcommand {element start} \ 64 -elementendcommand {element end} \ 65 -characterdatacommand pcdata \ 66 -processinginstructioncommand pi \ 67 -final yes \ 68] 69 70foreach {testName testData} [array get data] { 71 puts "*** $testName" 72 $parser reset 73 if {[catch {$parser parse $testData} err]} { 74 puts [list test failed due to $err] 75 } else { 76 puts [list test passed] 77 } 78} 79 80exit 0