here's an xml file:
<PDContainer type="h_list">
<element>
<s>step</s>
<f>0</f>
<s>mem</s>
<f>0</f>
<s>time-in</s>
<f>0</f>
<s>time-out</s>
<f>0</f>
<s>delay-in</s>
<f>0</f>
<s>delay-out</s>
<f>0</f>
<s>wait</s>
<f>0</f>
</element>
<element>
<s>step</s>
<f>1</f>
<s>mem</s>
<f>1</f>
<s>time-in</s>
<f>2</f>
<s>time-out</s>
<f>2</f>
<s>delay-in</s>
<f>0</f>
<s>delay-out</s>
<f>0</f>
<s>wait</s>
<f>0</f>
</element>
</PDContainer>
with the following code, i succeed to parse it in a text widget, and pushing the record button save the text back in xml format:
package require dom
toplevel .conduite
set var conduite
set viewFont "-*-courier-medium-r-normal--*-120-*-*-*-*-*-*"
frame .$var.view -bd 0 -relief flat
scrollbar .$var.vscroll -command ".$var.text yview"
text .$var.text -yscroll ".$var.vscroll set" -setgrid 1 -height 20 -width 80 \
-font $viewFont
pack .$var.view -expand yes -fill both
pack .$var.text -in .$var.view -side left -expand yes -fill both
pack .$var.vscroll -in .$var.view -side left -fill y
pack [button .$var.b -text "RECORD" -command SaveText ]
set ifd [open /Applications/D-light/data/conduite/new2-conduite.xml r]
set xml [read $ifd ]
set doc [dom:arse $xml ]
set csv {}
foreach total [dom::node selectNode $doc /PDContainer/element] {
append csv [dom::node stringValue $total]
}
.$var.text insert end $csv
package require tdom
set doc [dom createDocument PDContainer]
set root [$doc documentElement]
$root setAttribute type "h_list"
set rooty [dom createNodeCmd elementNode element]
dom createNodeCmd elementNode s
dom createNodeCmd elementNode f
dom createNodeCmd textNode t
set fileId [.conduite.text get 1.0 end]
proc SaveText {} {
global root fileId
$root appendFromScript {
element {
foreach coupe $fileId {
if {[string is integer $coupe]} {
f {t $coupe}
} else {
s {t $coupe}
}}
}
puts [$root asXML]
}
return
}
focus .$var.vscroll
but:
i don't succeed to make 2 <element> node as the original file.
i've tried to lookfor the blank space in the text widget, but it fail.
maybe the solution is to format the text widget horizontaly, and not vertically to, after, send each line to the SvaText proc.
but i don't know how to do.
please feel free to comment...
best regards
nicolas
<PDContainer type="h_list">
<element>
<s>step</s>
<f>0</f>
<s>mem</s>
<f>0</f>
<s>time-in</s>
<f>0</f>
<s>time-out</s>
<f>0</f>
<s>delay-in</s>
<f>0</f>
<s>delay-out</s>
<f>0</f>
<s>wait</s>
<f>0</f>
</element>
<element>
<s>step</s>
<f>1</f>
<s>mem</s>
<f>1</f>
<s>time-in</s>
<f>2</f>
<s>time-out</s>
<f>2</f>
<s>delay-in</s>
<f>0</f>
<s>delay-out</s>
<f>0</f>
<s>wait</s>
<f>0</f>
</element>
</PDContainer>
with the following code, i succeed to parse it in a text widget, and pushing the record button save the text back in xml format:
package require dom
toplevel .conduite
set var conduite
set viewFont "-*-courier-medium-r-normal--*-120-*-*-*-*-*-*"
frame .$var.view -bd 0 -relief flat
scrollbar .$var.vscroll -command ".$var.text yview"
text .$var.text -yscroll ".$var.vscroll set" -setgrid 1 -height 20 -width 80 \
-font $viewFont
pack .$var.view -expand yes -fill both
pack .$var.text -in .$var.view -side left -expand yes -fill both
pack .$var.vscroll -in .$var.view -side left -fill y
pack [button .$var.b -text "RECORD" -command SaveText ]
set ifd [open /Applications/D-light/data/conduite/new2-conduite.xml r]
set xml [read $ifd ]
set doc [dom:arse $xml ]
set csv {}
foreach total [dom::node selectNode $doc /PDContainer/element] {
append csv [dom::node stringValue $total]
}
.$var.text insert end $csv
package require tdom
set doc [dom createDocument PDContainer]
set root [$doc documentElement]
$root setAttribute type "h_list"
set rooty [dom createNodeCmd elementNode element]
dom createNodeCmd elementNode s
dom createNodeCmd elementNode f
dom createNodeCmd textNode t
set fileId [.conduite.text get 1.0 end]
proc SaveText {} {
global root fileId
$root appendFromScript {
element {
foreach coupe $fileId {
if {[string is integer $coupe]} {
f {t $coupe}
} else {
s {t $coupe}
}}
}
puts [$root asXML]
}
return
}
focus .$var.vscroll
but:
i don't succeed to make 2 <element> node as the original file.
i've tried to lookfor the blank space in the text widget, but it fail.
maybe the solution is to format the text widget horizontaly, and not vertically to, after, send each line to the SvaText proc.
but i don't know how to do.
please feel free to comment...
best regards
nicolas