title: Efficiently get the number of children with specific name using XML and R
body: <p>Using R and the package XML I'm parsing huge XML files. As part of the data handling I need to now, in a long list of nodes, how many children of specific name each node has (the number of nodes can exceed 20.000)</p>
  
  <p>My approach at the moment is:</p>
  
  <pre><code>nChildrenWithName &lt;- xpathSApply(doc, path="/path/to/node/*", namespaces=ns, xmlName) == 'NAME'
  nChildren &lt;- xpathSApply(doc, path="/path/to/node", namespaces=ns, fun=xmlSize)
  nID &lt;- sapply(split(nChildrenWithName, rep(seq(along=nChildren), nChildren)), sum)
  </code></pre>
  
  <p>Which is as vectorized as I can get it. Still I have the feeling that this can be achieved in a single call using the correct XPATH expression. My knowledge on XPATH is limited though, so if anyone knows how to do it I would be grateful for some insight...</p>
  
  <p>best Thomas</p>