title: nested XML to data frame in R
body: <p>Hello I'm new to R and XML files.</p>
  
  <p>I'm trying to get this XML SOAP response into a dataframe:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
    &lt;soap:Body&gt;
      &lt;PrepareDataByClientResponse xmlns="urn:HM-schema"&gt;
        &lt;PrepareDataByClientResult&gt;
          &lt;READOUT&gt;
            &lt;SerialNumber&gt;1728527&lt;/SerialNumber&gt;
            &lt;Date&gt;1510505992000&lt;/Date&gt;
            &lt;Type&gt;1&lt;/Type&gt;
            &lt;Value&gt;78.2&lt;/Value&gt;
            &lt;Status&gt;OK&lt;/Status&gt;
          &lt;/READOUT&gt;
          &lt;READOUT&gt;
            &lt;SerialNumber&gt;1728527&lt;/SerialNumber&gt;
            &lt;Date&gt;1510509592000&lt;/Date&gt;
            &lt;Type&gt;1&lt;/Type&gt;
            &lt;Value&gt;76.87&lt;/Value&gt;
            &lt;Status&gt;OK&lt;/Status&gt;
          &lt;/READOUT&gt;
          &lt;READOUT&gt;
            &lt;SerialNumber&gt;1728527&lt;/SerialNumber&gt;
            &lt;Date&gt;1510513192000&lt;/Date&gt;
            &lt;Type&gt;1&lt;/Type&gt;
            &lt;Value&gt;75.61&lt;/Value&gt;
            &lt;Status&gt;OK&lt;/Status&gt;
          &lt;/READOUT&gt;
          &lt;READOUT&gt;
            &lt;SerialNumber&gt;e2ddeed13b4cc4d132f8c6a67d67eed3&lt;/SerialNumber&gt;
            &lt;Date&gt;4531528776000&lt;/Date&gt;
            &lt;Type&gt;3&lt;/Type&gt;
            &lt;Value&gt;230.68&lt;/Value&gt;
            &lt;Status&gt;OK&lt;/Status&gt;
          &lt;/READOUT&gt;
        &lt;/PrepareDataByClientResult&gt;
          &lt;/PrepareDataByClientResponse&gt;
        &lt;/soap:Body&gt;
      &lt;/soap:Envelope&gt;
  </code></pre>
  
  <p>I have tried several options like:</p>
  
  <pre><code>xmlout &lt;- do.call(rbind, xpathApply(xmldoc,'//soap:Envelope/soap:Body/PrepareDataByClientResponse', xmlToDataFrame))
  xmlout &lt;- as.data.frame(t(xpathSApply(xmldoc,"//readout",function(x) xmlSApply(x,xmlValue))))
  xmlout &lt;- as.data.frame(t(xmlSApply(xmldoc["/PrepareDataByClientResponse/PrepareDataByClientResult/READOUT"],xmlAttrs)),stringsAsFactors=FALSE)
  xmlout &lt;- ldply(xmlToList(xmldoc), data.frame)
  </code></pre>
  
  <p>After extensive research in SO and other google searches, I have been unable to produce the desired results. All I can get is a data frame with a single row and all the observations in a different column each.</p>
  
  <p>I'm trying to get a table of READOUTS like:</p>
  
  <pre><code>    SerialNumber    Date            Type    Value    Status
  1   1728527         1510505992000   1       78.2     OK
  2   1728527         1510509592000   1       76.87    OK
  3   1728527         1510513192000   1       75.61    OK
  </code></pre>
  
  <p>Is there any way to get this sort of table to work?</p>
  
  <p>Thanks in advance.</p>