Posted to tcl by andrewsh at Thu Apr 15 06:56:38 GMT 2010view raw
- namespace eval some-parser {
- variable tagstack {}
- variable parser
- variable nodes
- variable id {}
-
- set parser [xml::parser]
-
- proc hs {name attlist} {
- variable tagstack
- catch {tag-$name $attlist}
- lappend tagstack $name
- }
-
- proc tag-node attlist {
- variable id [dict get $attlist id] \
- nodes($id) [dict create attrs [dict remove $attlist]]
- }
-
- $parser configure -elementstartcommand hs -elementendcommand he -characterdatacommand cdata
-
- proc parse xml {
- variable parser
- $parser parse $xml
- }
- }