Posted to tcl by andrewsh at Thu Apr 15 06:56:38 GMT 2010view raw

  1. namespace eval some-parser {
  2. variable tagstack {}
  3. variable parser
  4. variable nodes
  5. variable id {}
  6.  
  7. set parser [xml::parser]
  8.  
  9. proc hs {name attlist} {
  10. variable tagstack
  11. catch {tag-$name $attlist}
  12. lappend tagstack $name
  13. }
  14.  
  15. proc tag-node attlist {
  16. variable id [dict get $attlist id] \
  17. nodes($id) [dict create attrs [dict remove $attlist]]
  18. }
  19.  
  20. $parser configure -elementstartcommand hs -elementendcommand he -characterdatacommand cdata
  21.  
  22. proc parse xml {
  23. variable parser
  24. $parser parse $xml
  25. }
  26. }