::xox
Class XmlReader

Heritage:
::xotcl::Object
Direct Known Subclasses:
::xox::XmlNodeReader,

Class XmlReader
superclass ::xotcl::Object,
A library of methods that are useful when working with tDOM.
Variables
NameDefault ValueClassComment
 
Methods
NameComment
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

extractValue

Description:
 Extracts the text value of node.
Arguments:
Code:
  ::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
    
}

getFirstChildNamed

Description:
 Returns the dom node named name that is a child of node.
Arguments:
Code:
  ::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"
    
}

getFirstChildValueNamed

Description:
 Extracts the text of the first sub-node named name.

 Example:

     <node>
         <subnode>
         value
         </subnode>
     </node>

 $reader getFirstChildValueNamed $node subnode

 Will return: value
Arguments:
Code:
  ::xox::XmlReader instproc getFirstChildValueNamed {node name}  {
   

        return [ my extractValue [ my getFirstChildNamed $node $name ] ]
    
}

hasChildNamed

Description:
 Returns 1 if node has a child node named name. Returns 0 otherwise.
Arguments:
Code:
  ::xox::XmlReader instproc hasChildNamed {node name}  {
   

        foreach child [ $node childNodes ] {

            if { "[ $child nodeName ]" == "$name" } {

                return 1
            }
        }

        return 0
    
}