xml


do we have a TCL script to generate XML file?


i made a script using tcldom:
package require utils
package require testrunscheduler
package require tdom
tla::TSConfig::init -schedulerContext "Reporting" -environment production
tla::TSDBFactory::getConnection db
set testCaseList [$db doSQL "SELECT root_name,suite_name,case_name FROM ics where test_type = 'tce' limit 1"]
set item [join $testCaseList ""]
set doc [dom createDocument testCases]
set root [$doc documentElement]
set subnode [$doc createElement testCase]
$root appendChild $subnode
foreach item $item {
set node [$doc createElement root]
$node appendChild [$doc createTextNode $item]
$subnode appendChild $node
}
Output i get is :
<testCases>
<testCase>
<root>SPB</root>
<root>subscriberServices</root>
<root>jmsServices</root>
</testCase>
</testCases>
but i want output to be like :
<testCases>
<testCase>
<root>SPB</root>
<suite>subscriberServices</suite>
<case>jmsServices</case>
</testCase>
</testCases>
i used foreach for this, but it makes only for root, i am missing probably, this structure would iterate itself and grow as on the users input from sql query.
<testCases>
<testCase>
<root>demoRoot</root>
<suite>demoSuite</suite>
<case>demoCase</case>
<testCase>test_demo001</testCase>
</testCase>
<testCase>
<root>demoRoot</root>
<suite>demoSuite</suite>
<case>demoCase</case>
<testCase>test_demo002</testCase>
</testCase>
</testCases>
Please help me to get this kind of output, its very tedious to get this putput which is repetative but with one structure.
package require tdom
set data {
{demoRoot1 demoSuite1 demoCase1}
{demoRoot2 demoSuite2 demoCase2}
}
set doc [dom createDocument testCases]
set root [$doc documentElement]
dom createNodeCmd elementNode testCase
dom createNodeCmd elementNode root
dom createNodeCmd elementNode suite
dom createNodeCmd elementNode case
dom createNodeCmd textNode t
foreach line $data {
lassign $line _root suite case
# or (if you don't have lassign) foreach {_root suite case} $line break
$root appendFromScript {
testCase {
root {t $_root}
suite {t $suite}
case {t $case}
testCase {t [format {test_demo%03d} [incr num]]}
}
}
}
$doc asXML
Output:
<testCases>
<testCase>
<root>demoRoot1</root>
<suite>demoSuite1</suite>
<case>demoCase1</case>
<testCase>test_demo001</testCase>
</testCase>
<testCase>
<root>demoRoot2</root>
<suite>demoSuite2</suite>
<case>demoCase2</case>
<testCase>test_demo002</testCase>
</testCase>
</testCases>
See the tutorial on the wiki for more examples.
Documentation:
break,
foreach,
format,
if,
incr,
lassign,
package,
set,
tdom (package)

Related Links

Error in checkout - AddBodyClass
how to select attribute value of a node in xquery?
XSLT transformation using collection is missing context item
Overload extension methods of T
Permissions on XML execution missing?
XML Schema type alias?
Merge 2 input XML schemas into one CSV file - biztalk 2009
How to express this XML by json schema?
XSLT for loop or alternative for node duplication
XSL comparing and merging two XML stanzas
Selecting and merging XML data when having the same node name
Reformatting an XML with IntelliJ
XSD - Validate element which is a value of an attribute
Errors in building a RSS XML in Windows Using Word Pad
Access of possibly undefined property for XML objects in AS3?
Serializing Xml from Stream by Setting XmlRoot still throws Exception

Categories

HOME
url-redirection
xml
scikit-learn
gpu
pyqt
camera
jwplayer
sitecore
vscode-extensions
alarm
rom
babeljs
jetty
echo
elasticsearch-5
distribution
startup
coin3d
aws-sdk
nim
googlebot
ember-cli
visual-studio-extensions
exploit
direct3d11
tizen-tv
finagle
scrollview
dotspatial
complex-numbers
laravel-eloquent
jett
timing
z-notation
c9.io
ogc
stringtokenizer
parser-generator
movilizer
claims
lpsolve
ssrs-2014
file-sharing
flask-login
x++
gitlist
rserve
arq
pdf-conversion
check-mk
mathcad
google-cloud-console
adafruit
mongodb-php
jodd
jquery-jscrollpane
jtwig
lua-telegram-bot
cortex-m
ellucian-scribe
nullable
beanstalk
findfirst
httpruntime.cache
ascii-art
rasterize
avisynth
rewrite
morton-number
google-books
batik
skspritenode
snoop
nutiteq
angular-gettext
primitive-types
machine-instruction
human-computer-interface
xml-namespaces
koala
isqlquery
cffile
mvc-editor-templates
font-awesome-4.0.0
cardreader
curb
screen-size
workflow-services
htdocs
entitydatasource
tournament
clrstoredprocedure
event-receiver
cuteeditor
appledoc
undefined-index
folding
isapi-extension
entitykey
cardspace

Resources

Encrypt Message