TCL tdom xml向后解析直到根
我要编写一个tcl进程,其中我给出了一个xml的randon节点。我必须解析它的父母是否设置了特定的属性字段。在C++中,我可以用递归函数来轻松地完成这个操作。但在tdom中,我找不到如何检查是否已到达根节点TCL tdom xml向后解析直到根,xml,tcl,tdom,Xml,Tcl,Tdom,我要编写一个tcl进程,其中我给出了一个xml的randon节点。我必须解析它的父母是否设置了特定的属性字段。在C++中,我可以用递归函数来轻松地完成这个操作。但在tdom中,我找不到如何检查是否已到达根节点 /##I am just doing a rough in the following code. I wanted something like it ## proc testRecursive {XMLnode } { if { $XMLnode !=ROOTNODE} {
/##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
}
}
我是tcl的新手,所以语法不好,只是想传达这个想法。如何得到这个结果。请帮忙。这其实很简单:
proc testRecursive {XMLnode} {
set parent [$XMLnode parentNode]
if {$parent != ""} {
# Do your checks here
return [testRecursive $parent]
}
return "Default Value"
}
只需检查是否存在父节点。根节点没有父节点。您还可以检查两个
$node root
是否与$node
相同。这非常简单:
proc testRecursive {XMLnode} {
set parent [$XMLnode parentNode]
if {$parent != ""} {
# Do your checks here
return [testRecursive $parent]
}
return "Default Value"
}
只需检查是否存在父节点。根节点没有父节点。您还可以检查两个
$node root
是否与$node
相同