Posted to tcl by de at Tue Feb 13 23:54:43 GMT 2018view raw

  1.  
  2. tDOM::pullparser pp
  3. pp input {<doc><e1 a="b" foo:bar="c"><e2>foo</e2><e2></e2></e1><e1/></doc>}
  4. puts [pp state]
  5. while {[set state [pp next]] ne "END_DOKUMENT"} {
  6. puts -nonewline "$state "
  7. switch $state {
  8. "START_TAG" {
  9. puts [pp tag]
  10. foreach {attname attvalue} [pp attributes] {
  11. puts "\t$attname -> $attvalue"
  12. }
  13. }
  14. "TEXT" {
  15. puts [pp text]
  16. }
  17. "END_TAG" {
  18. puts [pp tag]
  19. }
  20. }
  21. }
  22. pp delete
  23.  
  24.  
  25. START_DOKUMENT
  26. START_TAG doc
  27. START_TAG e1
  28. a -> b
  29. foo:bar -> c
  30. START_TAG e2
  31. TEXT foo
  32. END_TAG e2
  33. START_TAG e2
  34. END_TAG e2
  35. END_TAG e1
  36. END_TAG e1
  37. END_TAG doc
  38. END_DOKUMENT
  39.