title: Counting XML nodes in R
body: <p>I'm trying to parse this XML table, but I'm having trouble counting the number of "var" nodes. My code so far is below. I would like to be able to replace the 16597 with a generalizable value so that I can use this code for other similar tables. I need to do this in R, not in XPATH.</p>
  
  <pre><code>require(RCurl)
  require(XML)
  url = "http://api.census.gov/data/2000/sf3/variables.xml"
  doc = xmlParse(url)
  root = xmlRoot(doc)
  xml.data = xmlToList(doc)
  
  id = NULL
  label = NULL
  concept = NULL
  for(i in 1:16597){
    id[i] = xml.data[[1]][[(i+2)]][["id"]]
    label[i] = xml.data[[1]][[(i+2)]][["label"]]
    concept[i] = xml.data[[1]][[(i+2)]][["concept"]]
  }
  
  scraped.data = data.frame(id, label, concept)
  </code></pre>
  
  <p>I tried this based off of <a href="https://stackoverflow.com/questions/15948339/efficiently-get-the-number-of-children-with-specific-name-using-xml-and-r">this question</a> but got 0. </p>
  
  <pre><code>doc &lt;- xmlTreeParse(url)
  xpathApply(xmlRoot(doc),path="count(//vars)",xmlValue)
  </code></pre>
  
  <p>Where is my misunderstanding? </p>