xmlDOMApply               package:XML               R Documentation

_A_p_p_l_y _f_u_n_c_t_i_o_n _t_o _n_o_d_e_s _i_n _a_n _X_M_L _t_r_e_e/_D_O_M.

_D_e_s_c_r_i_p_t_i_o_n:

     This recursively applies the specified function to each node in an
     XML tree, creating a new tree, parallel to the original input
     tree. Each  element in the new tree is the return value obtained
     from invoking the specified function on the corresponding element
     of the original tree. The order in which the function is
     recursively applied is "bottom-up". In other words,  function is
     first applied to each of the children nodes first and then to the 
     parent node containing the newly computed results for the
     children.

_U_s_a_g_e:

     xmlDOMApply(dom, func)

_A_r_g_u_m_e_n_t_s:

     dom: a node in the XML tree or DOM on which to recursively apply
          the given function. This should not be the 'XMLDocument'
          itself returned from 'xmlTreeParse' but an object of class
          'XMLNode'. This is typically obtained by calling 'xmlRoot' on
          the return value from 'xmlTreeParse'. 

    func: the function to be applied to each node in the XML tree. This
          is passed the node object for the and the return value is
          inserted into the new tree that is to be returned in the
          corresponding position as the node being processed. If the
          return value is 'NULL', this node is dropped from the tree.

_D_e_t_a_i_l_s:

     This is a native (C code) implementation that  understands the
     structure of an XML DOM returned from 'xmlTreeParse' and iterates
     over the nodes in that tree.

_V_a_l_u_e:

     A tree that parallels the structure in the  'dom' object passed to
     it.

_A_u_t_h_o_r(_s):

     Duncan Temple Lang

_R_e_f_e_r_e_n_c_e_s:

     <URL: http://www.w3.org/XML>, <URL: http://www.jclark.com/xml>,
     <URL: http://www.omegahat.org>

_S_e_e _A_l_s_o:

     xmlTreeParse

_E_x_a_m_p_l_e_s:

      dom <- xmlTreeParse(system.file("exampleData","mtcars.xml", package="XML"))
      tagNames <- function() {
         tags <- character(0)
         add <- function(x) {
           if(inherits(x, "XMLNode")) {
             if(is.na(match(xmlName(x), tags)))
                tags <<- c(tags, xmlName(x))
           }

           NULL
         }

         return(list(add=add, tagNames = function() {return(tags)}))
      }

      h <- tagNames()
      xmlDOMApply(xmlRoot(dom), h$add) 
      h$tagNames()

