xmlTree                 package:XML                 R Documentation

_A_n _i_n_t_e_r_n_a_l, _u_p_d_a_t_a_b_l_e _D_O_M _o_b_j_e_c_t _f_o_r _b_u_i_l_d_i_n_g _X_M_L _t_r_e_e_s

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

     This is a mutable object (implemented via a closure) for
     representing an XML tree, in the same spirit as 'xmlOutputBuffer'
     and 'xmlOutputDOM' but that uses the internal structures of
     libxml. This can be used to create a DOM that can be  constructed
     in R and exported to another system such as XSLT (<URL:
     http://www.omegahat.org/Sxslt>)

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

     xmlTree(tag, attrs = NULL, dtd=NULL, namespaces=list())

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

     tag: the tagname of the top-level element. This is basically
          ignored!

   attrs: attributes for the top-level node, in the form of a named
          vector or list.

     dtd: the name of the external DTD for this document. See
          'newXMLDoc'

namespaces: a named character vector with each element giving the name
          space identifier and the corresponding URI, \ e.g 'c(shelp =
          "http://www.omegahat.org/XML/SHelp")'

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

     This creates a collection of functions that manipulate a shared
     state to build and maintain an XML tree in C-level code.

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

     An object of class 'XMLInternalDOM' that extends 'XMLOutputStream'
     and has the same interface (i.e. ``methods'') as 'xmlOutputBuffer'
      and 'xmlOutputDOM'. Each object has methods for  adding a new XML
     tag,  closing a tag, adding an XML comment, and retrieving the
     contents of the tree. 

  addTag: create a new tag at the current position, optionally leaving
          it as the active open tag to which new nodes will be added as
          children

closeTag: close the currently active tag making its parent the active
          element into which new nodes will be added.

addComment: add an XML comment node as a child of the active node in
          the document.

   value: retrieve an object representing the  XML tree. See 'saveXML'
          to serialize the contents of the tree.

     add: degenerate method in this context.

_N_o_t_e:

     This is an early version of this function and I need to iron out
     some of the minor details.

_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.xmlsoft.org>, <URL:
     http://www.omegahat.org>

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

     'saveXML' 'newXMLDoc' 'newXMLNode' 'xmlOutputBuffer'
     'xmlOutputDOM'

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

       tr <- xmlTree("Duncan")
       tr$addTag("name", attrs=c(a=1,b="xyz"), close=FALSE)
         tr$addTag("first", "Larry")
         tr$addTag("last", "User")
       tr$closeTag()
       tr$value()
       cat(saveXML(tr$value()))

       tr <- xmlTree("CDataTest")
       tr$addTag("top", close=FALSE)
       tr$addCData("x <- list(1, a='&');\nx[[2]]")
       tr$addPI("S", "plot(1:10)")
       tr$closeTag()
       cat(saveXML(tr$value()))

