title: How convert a data.frame into a xml file with R?
body: <p>I have a simple data.frame with two variables, title and base64. I need to transform this data.frame into XML format. For example heres what my data looks like.. </p>
  
  <pre><code>str(df)
       'data.frame':  2 obs. of  2 variables:
       $ title  : chr  "Page One" "Page Two"
       $ base64: chr  "Very Long String thats a base64 character" "Very Long String thats a base64 character"
  </code></pre>
  
  <blockquote>
    <p>dput(df)
        structure(list(page = c("Page One", "Page Two"), base64 = c("Very Long String thats a base64 character", 
        "Very Long String thats a base64 character")), .Names = c("page", 
        "base64"), row.names = 1:2, class = "data.frame")</p>
  </blockquote>
  
  <p>I need to output a XML file that has a format that looks like this... </p>
  
  <pre><code>&lt;report type="enchanced"&gt;
      &lt;pages&gt;
          &lt;page&gt;
              &lt;title&gt;Page One&lt;/title&gt;
              &lt;page&gt; *** long base64 string *** &lt;/page&gt;
          &lt;/page&gt;
          &lt;page&gt;
              &lt;title&gt;Page Two&lt;/title&gt;
              &lt;page&gt; *** long base64 string *** &lt;/page&gt;
          &lt;/page&gt;
      &lt;/pages&gt;
  &lt;/report&gt;
  </code></pre>
  
  <p>I've been experimenting with the XML package in R and even found this function that seems like it should work, but I cannot figure it out. Any help is greatly appreciated. </p>
  
  <pre><code>library(XML)
  convertToXML &lt;- function(df,name) {
    xml &lt;- xmlTree("report")
    xml$addNode(name, close=FALSE)
    for (i in 1:nrow(df)) {
      xml$addNode("page", close=FALSE)
      for (j in names(df)) {
        xml$addNode(j, df[i, j])
      }
      xml$closeTag()
    }
    xml$closeTag()
    return(xml)
  }
  
   tr = convertToXML(df,"pages") 
   cat(saveXML(tr$page())) ## suppose to looks good
  </code></pre>