EVOLUTION-MANAGER
Edit File: addSibling.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Manipulate sibling XML nodes</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for getSibling {XML}"><tr><td>getSibling {XML}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Manipulate sibling XML nodes</h2> <h3>Description</h3> <p>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 </p> <h3>Usage</h3> <pre> getSibling(node, after = TRUE, ...) addSibling(node, ..., kids = list(...), after = NA) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>node</code></td> <td> <p>the internal XML node (XMLInternalNode) whose siblings are of interest</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>the XML nodes to add as siblings or children to node.</p> </td></tr> <tr valign="top"><td><code>kids</code></td> <td> <p>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 <code>addSibling</code> rather interactive use where we more commonly have the individual node objects. </p> </td></tr> <tr valign="top"><td><code>after</code></td> <td> <p>a logical value indicating whether to retrieve or add the nodes to the right (<code>TRUE</code>) or to the left (<code>FALSE</code>) of this sibling. </p> </td></tr> </table> <h3>Value</h3> <p><code>getSibling</code> returns an object of class XMLInternalNode (or some derived S3 class, e.g. XMLInternalTextNode) </p> <p><code>addSibling</code> returns a list whose elements are the newly added XML (internal) nodes. </p> <h3>See Also</h3> <p><code><a href="xmlChildren.html">xmlChildren</a></code>, <code><a href="addChildren.html">addChildren</a></code> <code><a href="addChildren.html">removeNodes</a></code> <code><a href="addChildren.html">replaceNodes</a></code> </p> <h3>Examples</h3> <pre> # 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 = xmlParse(fileName) nodes = getNodeSet(doc, "//key[text() = 'Artist']") sapply(nodes, function(x) xmlValue(getSibling(x))) f = system.file("exampleData", "simple.xml", package = "XML") tt = as(xmlParse(f), "XMLHashTree") tt e = getSibling(xmlRoot(tt)[[1]]) # and back to the first one again by going backwards along the sibling list. getSibling(e, after = FALSE) # This also works for multiple top-level "root" nodes f = system.file("exampleData", "job.xml", package = "XML") tt = as(xmlParse(f), "XMLHashTree") x = xmlRoot(tt, skip = FALSE) getSibling(x) getSibling(getSibling(x), after = FALSE) </pre> <hr /><div style="text-align: center;">[Package <em>XML</em> version 3.99-0.3 <a href="00Index.html">Index</a>]</div> </body></html>