getSibling                package:XML                R Documentation

_M_a_n_i_p_u_l_a_t_e _s_i_b_l_i_n_g _X_M_L _n_o_d_e_s

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

     These functions allow us to both access the sibling node to the
     left or right of a given node and so walk the chain of siblings,
     and also to insert a new sibling

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

     getSibling(node, after = TRUE)
     addSibling(node, ..., kids = list(...), after = NA)

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

    node: the internal XML node (XMLInternalNode)  whose siblings are
          of interest

     ...: the XML nodes to add as siblings or children to node.

    kids: a list containing the XML nodes to add as siblings. This is
          equivalent to ... but used when we already have the nodes in
          a list rather than as individual objects. This is used in
          programmatic calls to  'addSibling' rather interactive use
          where we more commonly have the individual node objects. 

   after: a logical value indicating whether to retrieve or add the 
          nodes to the right ('TRUE') or to the left ('FALSE') of this
          sibling. 

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

     'getSibling' returns an object of class XMLInternalNode (or some
     derived S3 class, e.g. XMLInternalTextNode)

     'addSibling' returns a list whose elements are the newly added XML
     (internal) nodes.

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

     'xmlChildren', 'addChildren' 'removeNodes' 'replaceNodes'

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

       
               # Reading Apple's iTunes files
          # 
          #           Here we read  a "censored" "database" of songs from Apple's  iTune application
          #           which is stored in a property list.  The format is quite generic and 
          #            the fields for each song are given in the form
          #           
          #             <key>Artist</key><string>Person's name</string>
          #    
          #           So to find the names of the artists for all the songs, we want to 
          #           find all the <key>Artist<key> nodes and then get their next sibling
          #           which has the actual value.
          #         
          #           More information can be found in .
          #  
                fileName = system.file("exampleData", "iTunes.plist", package = "XML")

                doc = xmlTreeParse(fileName, useInternal = TRUE)
                nodes = getNodeSet(doc, "//key[text() = 'Artist']")
                sapply(nodes, function(x)  xmlValue(getSibling(x)))
             
        

