I have a one tcl proc to write where I have given one randon node of a xml. I have to parse its parents whether they have a particular attribute field is set or not.In C++ I can easily do this using recursive function which breaks when ROOT node is reached. But in tdom I can not find how to check whether Root node has been reached or not.
/##I am just doing a rough in the following code. I wanted something like it ##
proc testRecursive {XMLnode } {
if { $XMLnode !=ROOTNODE} {
set ParentND [$XMLnode parentNode]
/#some checkings and other actions done here
testRecursive ParentND
} else {
exit
}
}
I am new to tcl ,so syntaxs are not good, just wanted to convey the idea. How to get this result . please help.
It is acutally really simple:
proc testRecursive {XMLnode} {
set parent [$XMLnode parentNode]
if {$parent != ""} {
# Do your checks here
return [testRecursive $parent]
}
return "Default Value"
}
Just check if there is a parent node. The root node has no parent node.
You can also check if both $node root
is the same as $node
.