xmlToList                package:XML                R Documentation

_C_o_n_v_e_r_t _a_n _X_M_L _n_o_d_e/_d_o_c_u_m_e_n_t _t_o _a _m_o_r_e _R-_l_i_k_e _l_i_s_t

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

     This function is an early and simple approach to converting an XML
     node or document into a more typical R list containing the data
     values directly (rather than as XML nodes). It is useful for
     dealing with data that is returned from REST requests or other Web
     queries or generally when parsing XML and wanting to  be able to
     access the content as elements in a list indexed by the name of
     the node. For example, if given a node of the form ' <x>
     <a>text</a> <b foo="1"/> <c bar="me"> <d>a phrase</d> </c> </x> '
     We would end up with a list with elements named "a", "b" and "c".
     "a" would be the string "text", b would contain the named
     character vector 'c(foo = "1")' (i.e. the attributes) and "c"
     would contain the list with two elements named "d" and ".attrs".
     The element corresponding to "d" is a character vector with the
     single element "a phrase".  The ".attrs" element of the list is
     the character vector of attributes from the node '<c>...</c>'.

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

     xmlToList(node, addAttributes = TRUE)

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

    node: the XML node or document to be converted to an R list. This
          can be an "internal" or C-level node (i.e.
          'XMLInternalNode-class') or a regular R-level node (either
          'XMLNode-class' or 'XMLHashNode').

addAttributes: a logical value which controls whether the attributes of
          an empty node are added to the 

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

     A list whose elements correspond to the children of the top-level
     nodes.

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

     Duncan Temple Lang

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

     'xmlTreeParse' 'getNodeSet' and 'xpathApply' 'xmlRoot', 
     'xmlChildren',  'xmlApply', '[[', etc. for accessing the content
     of XML nodes.

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

     tt = 
      '<x>
          <a>text</a>
          <b foo="1"/>
          <c bar="me">
             <d>a phrase</d>
          </c>
       </x>'

       doc = xmlParse(tt)
       xmlToList(doc)

       doc = xmlTreeParse(tt)
       xmlToList(doc)

