1#!/bin/sh 2# -*- tcl -*- \ 3exec tclsh "$0" "$@" 4 5# simple.tcl -- 6# 7# Count the characters in a XML document, 8# from README. 9# 10# Copyright (c) 2008 Explain 11# http://www.explain.com.au/ 12# 13# $Id$ 14 15package require xml 3.2 16 17 18set parser [xml::parser] 19$parser configure -elementstartcommand EStart \ 20 -characterdatacommand PCData 21 22proc EStart {tag attlist args} { 23 array set attr $attlist 24 puts "Element \"$tag\" started with [array size attr] attributes" 25} 26 27proc PCData text { 28 incr ::count [string length $text] 29} 30 31set count 0 32$parser parse [read stdin] 33 34puts "The document contains $count characters" 35exit 0 36 37