#!/usr/bin/tclsh package require tdom set xmlFile ./Sim.SimInfo set txtFile ./graph.txt set pngFile ./graph.png set size [file size $xmlFile] set fd [open $xmlFile] set xml [read $fd $size] close $fd set doc [dom parse -simple $xml] set root [$doc documentElement] set fh [open $txtFile "w"] puts $fh "digraph finite_state_machine {" puts $fh "size=\"7,7\";" foreach connection [$root selectNodes Connection] { set command "" set SourceId [[$connection child 1 Source] getAttribute id] set SourceName [[$root find id $SourceId] getAttribute Name] set TargetId [[$connection child 1 Target] getAttribute id] set TargetName [[$root find id $TargetId] getAttribute Name] append command $SourceName " -> " $TargetName set InputNr [[$connection child 1 InputNumber] getAttribute value] switch $InputNr { 0 {} 1 {append command " \[arrowhead = tee\]"} 2 {} 3 {append command " \[arrowhead = tee\]"} } append command " ;" puts $fh $command } puts $fh "}" close $fh exec dot -Tpng $txtFile -o $pngFile $doc delete