title: In R, how can I loop over repeated XML nodes, and save text values in a list?
body: <p>I'm working with XML files from clinicaltrials.gov, which have a structure like this: </p>
  
  <pre><code>&lt;clinical_study&gt;
    ...
    &lt;brief_title&gt;
    ...
    &lt;location&gt;
      &lt;facility&gt;
        &lt;name&gt;
        &lt;address&gt;
          &lt;city&gt;
          &lt;state&gt;
          &lt;zip&gt;
          &lt;country&gt;
      &lt;/facility&gt;
    &lt;/location&gt;
    &lt;location&gt;
      ...
    &lt;/location&gt;
    ...
  &lt;/clinical_study&gt;
  </code></pre>
  
  <p>I'm gathering information from multiple XML files, so the number of locations in each file is unknown and could even be zero.  I need to extract all the information about each location and save into an SQL table. I've had some success using functions from the XML package to extract information from single nodes, e.g. </p>
  
  <pre><code>library(XML)
  nct_url &lt;- "http://clinicaltrials.gov/ct2/show/NCT00112281?resultsxml=true"
  xml_doc &lt;- xmlParse(nct_url, useInternalNode=TRUE)
  title_path &lt;- "/clinical_study/brief_title" 
  title_text &lt;- xpathSApply(xml_doc, title_path, xmlValue)
  </code></pre>
  
  <p>I'm experimenting with getNodeSet, and this gives me a set of the right length: </p>
  
  <pre><code>doc &lt;- xmlParse("NCT00007501.xml")
  locations &lt;- getNodeSet(doc, "/clinical_study/location")
  length(locations)
  [1] 22
  &gt; class(locations)
  [1] "XMLNodeSet"
  </code></pre>
  
  <p>but my attempts to extract information from this set have been mostly fruitless.  Any suggestions?</p>