title: r xml get following attrib value after specific node
body: <p>I am trying to parse all action nodes out of an xml file and add the following atbat num value.  I have a section of an xml file below.  I have the code working to grab all the actions, I just can't figure out how to add the following atbat num to the list/dataframe.  I believe it is a sibling node, not a parent/child node because the actions are not nested under one of the atbat nodes.  The code I'm using is this  I have tried to incorporate following-sibling not equal to action, but couldn't only return errors.  It should pull all values from each action node, append the gameid (it already does this), and append the following atbat num value.</p>
  
  <pre><code>url &lt;- "http://gd2.mlb.com/components/game/mlb/year_2015/month_05/day_20/gid_2015_05_20_tbamlb_atlmlb_1/inning/inning_all.xml"
  
  
  mlb &lt;- read_xml(url)
  
  # get all at-bats ---------------------------------------------------------
  
  atbat &lt;- try(xml_find_all(mlb, "//action"), silent = FALSE)
  
  bind_rows(lapply(atbat, function(y) {
      data.frame(t(xml_attrs(y)), stringsAsFactors=FALSE)
  })) -&gt; pitch_dat
  
  game_id = substr(url, 66, 95)
  pitch_dat$game_id &lt;- game_id
  
  batsdf &lt;- data.frame(pitch_dat)
  </code></pre>
  
  <p>xml example</p>
  
  <pre><code>&lt;atbat num="44" b="4" s="0" o="2" start_tfs="004231" start_tfs_zulu="2015-05-21T00:42:31Z" batter="452678" stand="R" b_height="6-0" pitcher="501593" p_throws="L" des="Luis Avilan intentionally walks Asdrubal Cabrera. " des_es="Luis Avilan recibe base por bolas intencional Asdrubal Cabrera. " event_num="333" event="Intent Walk" event_es="Base por Bolas Intencional" play_guid="86cdbf1e-049e-4eb6-9314-85cfb3e6e28a" home_team_runs="1" away_team_runs="1"&gt;...&lt;/atbat&gt;
  &lt;action b="4" s="0" o="2" des="Coaching visit to mound. " des_es="Visita del Instructor a la Lomita" event="Game Advisory" event_es="Aviso en el Juego" tfs="004848" tfs_zulu="2015-05-21T00:48:48Z" player="425784" pitch="4" event_num="334" home_team_runs="1" away_team_runs="1"/&gt;
  &lt;action b="0" s="0" o="2" des="Pitching Change: Brandon Cunniff replaces Luis Avilan, batting 9th. " des_es="Cambio de Lanzador: Brandon Cunniff reemplaza a Luis Avilan, bateando noveno. " event="Pitching Substitution" event_es="Cambio de Lanzador" tfs="004904" tfs_zulu="2015-05-21T00:49:04Z" player="594792" pitch="4" event_num="336" home_team_runs="1" away_team_runs="1"/&gt;
  &lt;action b="0" s="0" o="2" des="Offensive Substitution: Pinch-hitter Nick Franklin replaces Rene Rivera. " des_es="Sustitución a la ofensiva: bateador emergente Nick Franklin reemplaza a Rene Rivera. " event="Offensive Sub" event_es="Cambio Defensivo" tfs="004924" tfs_zulu="2015-05-21T00:49:24Z" player="545338" pitch="4" event_num="338" home_team_runs="1" away_team_runs="1"/&gt;
  &lt;atbat num="45" b="0" s="1" o="3" start_tfs="004934" start_tfs_zulu="2015-05-21T00:49:34Z" batter="545338" stand="L" b_height="6-1" pitcher="594792" p_throws="R" des="Nick Franklin grounds out softly to first baseman Freddie Freeman. " des_es="Nick Franklin batea rodado de out suavemente a primera base Freddie Freeman. " event_num="343" event="Groundout" event_es="Roletazo de Out" home_team_runs="1" away_team_runs="1"&gt;...&lt;/atbat&gt;
  </code></pre>
  
  <p><a href="http://gd2.mlb.com/components/game/mlb/year_2015/month_05/day_20/gid_2015_05_20_tbamlb_atlmlb_1/inning/inning_all.xml" rel="nofollow">Full XML</a></p>
  
  <p>What I would like to end up with, the atbatnum field is filled with made up data for example purposes.</p>
  
  <pre><code>Variables:
  $ b              (chr) "1", "0", "0", "4", "0", "0", "0", "0", "0", "0", "4", "1", "0", "0", "0", "0", "0"
  $ s              (chr) "1", "0", "0", "0", "0", "0", "0", "0", "0", "0", "2", "2", "0", "0", "0", "0", "0"
  $ o              (chr) "1", "2", "0", "2", "2", "2", "0", "0", "0", "1", "2", "2", "0", "0", "0", "0", "2"
  $ des            (chr) "Coaching visit to mound.  ", "Offensive Substitution: Pinch-hitter Adonis Garcia replaces Williams Perez.  ", "Pitchi...
  $ des_es         (chr) "Visita del Instructor a la Lomita", "Sustitución a la ofensiva: bateador emergente Adonis Garcia reemplaza a Williams...
  $ event          (chr) "Game Advisory", "Offensive Sub", "Pitching Substitution", "Game Advisory", "Pitching Substitution", "Offensive Sub", ...
  $ event_es       (chr) "Aviso en el Juego", "Cambio Defensivo", "Cambio de Lanzador", "Aviso en el Juego", "Cambio de Lanzador", "Cambio Defe...
  $ tfs            (chr) "001915", "002757", "003536", "004848", "004904", "004924", "005010", "005949", "010446", "011004", "011539", "011723"...
  $ tfs_zulu       (chr) "2015-05-21T00:19:15Z", "2015-05-21T00:27:57Z", "2015-05-21T00:35:36Z", "2015-05-21T00:48:48Z", "2015-05-21T00:49:04Z"...
  $ player         (chr) "519306", "611177", "501593", "425784", "594792", "545338", "435064", "542994", "544993", "465674", "430948", "607054"...
  $ pitch          (chr) "3", "3", "5", "4", "4", "4", "2", "4", "2", "2", "10", "3", "4", "4", "1", "6", "6"
  $ event_num      (chr) "253", "283", "306", "334", "336", "338", "347", "386", "404", "420", "442", "449", "456", "458", "490", "515", "532"
  $ home_team_runs (chr) "1", "1", "1", "1", "1", "1", "1", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2"
  $ away_team_runs (chr) "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1"
  $ play_guid      (chr) NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, "c99d1e25-008f-4c46-aff0-d9e9e8548664", NA, NA, NA, NA, NA
  $ game_id        (chr) "gid_2015_05_20_tbamlb_atlmlb_1", "gid_2015_05_20_tbamlb_atlmlb_1", "gid_2015_05_20_tbamlb_atlmlb_1", "gid_2015_05_20_...
  $ atbat_num      (chr)  "1","12","13","24","24","34","35...
  </code></pre>
  
  <p>Any help is greatly appreciated!!  Thanks!</p>