-
Notifications
You must be signed in to change notification settings - Fork 1
Home
Omar-Medina edited this page Jul 16, 2024
·
2 revisions
Welcome to the xmlgen.tcl wiki!
Example to generate the following XML-file:
<rootElement>
<ab at0="abc" at1="def" at2="fgh" at3="dfr ds">>Es ist ein Text&1</ab>
<ab at0="abc" at1="def" at2="fgh" at3="dfr gh">>Es ist ein Text&1</ab>
<ab at0="abc" at1="def" at2="fgh" at3="dfr AB">>Es ist ein <Tex&&t1</ab>
<ab n="e0">>Es ist ei<n Text&</ab>
</rootElement>
writeXML.tcl
package require xmlgen
proc generateContent {} {
set text [ ::xmlgen::esc ">Es ist ein Text&1" ]
::xmlgen::doTag ab at0=abc at1=def at2=fgh {at3=dfr ds} - $text
::xmlgen::doTag ab at0=abc at1=def at2=fgh at3=dfr\ gh - $text
set text [ ::xmlgen::esc ">Es ist ein <Tex&&t1" ]
set lstAtt [list]
lappend lstAtt ::xmlgen::doTag
lappend lstAtt ab
lappend lstAtt at0=abc
lappend lstAtt at1=def
lappend lstAtt at2=fgh
lappend lstAtt "at3=dfr AB"
lappend lstAtt -
lappend lstAtt $text
eval $lstAtt
set text [ ::xmlgen::esc ">Es ist ei<n Text&" ]
::xmlgen::doTag ab n=e0 - $text
}
set xmlfile [ open xxx.xml w+ ]
::xmlgen::channel $xmlfile {
::xmlgen::doTag rootElement {} ! {
generateContent
}
}
close $xmlfile
Take care if the attribute value contains space-sign.