title: XML parsing in R - recursive decent on attributes of children nodes
body: <p>I'm new to XML parsing and have worked through a variety of tutorials. Right now, I am trying to parse an XML document from search results from the PsychInfo database.  Basically, what I want are the attributes of each article saved into a data frame that can be easily analyzed.  However, my XML document has has a nesting structure that I don't fully understand.  </p>
  
  <p>Here is my specific problem.  <strong><em>EDITED BASED ON SUGGESTION FROM MR.FLICK</em></strong></p>
  
  <p>I want to access all the attributes of the nodes of the children in the XML file -- e.g., article title (btl), publication date (pubinfo), author (au), etc.  When I apply the function <code>xmlChildren</code> to the root node, it returns only one item.  As suggested by MrFlick in the comment, I will need to set up some form of recursive descent to extract these other attributes.  These other attributes would then be saved in a data frame.  </p>
  
  <p>Provided below is the code I have been using, followed by a specific example of what I am hoping to achieve.  </p>
  
  <pre><code>library(XML)
  library(RCurl) 
  
  read.url &lt;- function(url, ...){
      tmpFile &lt;- tempfile()
      download.file(url, destfile = tmpFile, method = "curl")
      url.data &lt;- xmlParse(tmpFile, ... )
      return(url.data)
      }
  </code></pre>
  
  <p>Here is the full path to the data on Gist.  (Attempts at shortening with bit.ly prevents it from being properly read. Any suggestions on addressing this secondary problem would be helpful!)</p>
  
  <p>DF &lt;- read.url("<a href="https://gist.githubusercontent.com/beperron/e75a17e653ed668211bd/raw/2c4c31e0200c080094353d318e8e0ee59dce60fa/PsychInfo" rel="nofollow">https://gist.githubusercontent.com/beperron/e75a17e653ed668211bd/raw/2c4c31e0200c080094353d318e8e0ee59dce60fa/PsychInfo</a>")</p>
  
  <p>The following code first checks to see that it is of the XML document class.  The subsequent code extracts the root nodes and children.  </p>
  
  <pre><code>class(DF) #Check to see it is an XML document
  RootNode &lt;- xmlRoot(DF) #Obtain root node
  ChildNodes &lt;- xmlChildren(RootNode) #Obtain children of root
  </code></pre>
  
  <p>This code examines the first child of the root node:</p>
  
  <pre><code>pietyScale &lt;- ChildNodes[[1]] 
  xmlName(pietyScale)
  xmlSize(pietyScale)
  xmlAttrs(pietyScale)
  xmlValue(pietyScale)
  xmlChildren(pietyScale)
  xmlAttrs(pietyScale) 
  </code></pre>
  
  <p>As indicated, the <code>xmlAttrs</code> returns only one item, resultID.  The information that I need is nested within each child.  The data frame I am seeking to extract based on the following tags: rec resultID, btl, jtl, pubinfo, doi.  I want to extract a lot more information, but this would certainly be enough to get me going in the right direction.  </p>
  
  <pre><code>ID            1     
  title         "Development and evaluation of the Arabic Filial Piety Scale"
  journal       "Research on Social Work Practice"  
  pubdate       "2010-07-01" 
  doi           "10.1177/1049731510369495"
  </code></pre>