Q:

How to insert a node html before and after a node in R

I have the following  situation? 
require(xml2)

sup_before <- read_xml("<sup>R$</sup>")
sup_after <- read_xml("<sup>,00</sup>")

node <- read_xml('<tr>
    <td style="text-align:center;" class="alter_table"> 555563 </td>
    <td style="text-align:center;" class="alter_table"> 1217298 </td></tr>
')

I wanna put in a sup html code, before and after a value number like that.
Results - 
<td style="text-align:center;" class="alter_table"> <sup>R$</sup> 555563 <sup>,00</sup> </td>

<td style="text-align:center;" class="alter_table"> <sup>R$</sup>1217298<sup>,00</sup> </td>

A:

One technique is to grab the text nodes in the <td> tags and insert siblings nodes before and after with the data you want. For example
for (tdtext in xml_find_all(node, "td/text()")) {
  xml_add_sibling(tdtext, sup_before, .where="before")
  xml_add_sibling(tdtext, sup_after, .where="after")
}

