00001 /* !/bin/sh*/ 00002 /* -*- tcl -*- \*/ 00003 exec tclsh "$0" "$@" 00004 00005 /* simple.tcl --*/ 00006 /* */ 00007 /* Simple character count of a DOM document,*/ 00008 /* from README.*/ 00009 /* */ 00010 /* Copyright (c) 2008 Explain*/ 00011 /* http://www.explain.com.au/*/ 00012 /* */ 00013 /* $Id$*/ 00014 00015 package require xml 3.2 00016 00017 doc = [dom::parse [read stdin]] 00018 count = 0 00019 foreach textNode [dom::selectNode $doc //text()] { 00020 incr count [string length [$textNode cget -nodeValue]] 00021 } 00022 00023 puts "The document contains $count characters" 00024 exit 0 00025 00026