|
||||||
| SUMMARY: CHILDREN | PARAMETER | INSTPROC | INSTFILTER | INSTFORWARD | DETAIL: | INSTPROC | |||||
::xotcl::Object
A library of methods that are useful when working with tDOM.
| Variables | |||
| Name | Default Value | Class | Comment |
| Methods | |
| Name | Comment |
extractValue {node}
| Extracts the text value of node |
getFirstChildNamed {node name}
| Returns the dom node named name that is a child of node |
getFirstChildValueNamed {node name}
| Extracts the text of the first sub-node named name |
hasChildNamed {node name}
| Returns 1 if node has a child node named name |
| Methods from ::xotcl::Object |
#, ., ?, ?code, ?methods, ?object, abstract, copy, coverageFilter, defaultmethod, extractConfigureArg, filterappend, garbageCollect, get#, getClean#, hasclass, init, methodTag, mixinappend, move, profileFilter, self, setParameterDefaults, shell, tclcmd, traceFilter,
|
| Instproc Detail |
Extracts the text value of node.
node ::xox::XmlReader instproc extractValue {node} {
set childNodes [ $node childNodes ]
if { [ llength $childNodes ] == 0 } {
return ""
}
if { [ llength $childNodes ] == 1 } {
set value [ string trim [ $childNodes nodeValue ] ]
} else {
error "Bad node: [ $node nodeName ]"
}
return $value
}
Returns the dom node named name that is a child of node.
node name ::xox::XmlReader instproc getFirstChildNamed {node name} {
foreach child [ $node childNodes ] {
if { "[ $child nodeName ]" == "$name" } {
return $child
}
}
error "Did not find a child of $node with name $name"
}
Extracts the text of the first sub-node named name.
Example:
<node>
<subnode>
value
</subnode>
</node>
$reader getFirstChildValueNamed $node subnode
Will return: valuenode name ::xox::XmlReader instproc getFirstChildValueNamed {node name} {
return [ my extractValue [ my getFirstChildNamed $node $name ] ]
}
Returns 1 if node has a child node named name. Returns 0 otherwise.
node name ::xox::XmlReader instproc hasChildNamed {node name} {
foreach child [ $node childNodes ] {
if { "[ $child nodeName ]" == "$name" } {
return 1
}
}
return 0
}