title: R: How to best extract two XML attributes from a node?
body: <p>The following code extracts one attribute (or all) from an XML file:</p>
  
  <pre><code>library(xml2);library(magrittr);library(readr);library(tibble);library(knitr)   
  fname&lt;-'https://raw.githubusercontent.com/wardblonde/ODM-to-i2b2/master/odm/examples/CDISC_ODM_example_3.xml'
  fname
  x&lt;-read_xml(fname)
  xpath="//d1:ItemDef"
  itemsNames &lt;- x %&gt;% xml_find_all(xpath, ns=xml_ns(x)) %&gt;%  xml_attr('Name')
  items &lt;- x %&gt;% xml_find_all(xpath, ns=xml_ns(x))
  </code></pre>
  
  <p>Item looks like this:</p>
  
  <pre><code>&lt;ItemDef OID="IT.ABNORM" Name="Normal/Abnormal/Not Done" DataType="integer" Length="1" ...
  </code></pre>
  
  <p>Sample file can be viewed here: <a href="https://raw.githubusercontent.com/wardblonde/ODM-to-i2b2/master/odm/examples/CDISC_ODM_example_3.xml" rel="nofollow noreferrer">https://raw.githubusercontent.com/wardblonde/ODM-to-i2b2/master/odm/examples/CDISC_ODM_example_3.xml</a></p>
  
  <p>Using pipes and xml_attr, what is the best way to extract both the <code>Name</code> and <code>DataType</code> attributes and have them rbinded?</p>
  
  <p>Ideally it would be a single line of super efficient piped code. I can extract names and types and have 'data.frame(name=names,type=types)' but that seems not the best and most modern.</p>
  
  <p>The result should be a tibble with columns name and data type. </p>