views:

44

answers:

1

I have some data which looks like:

<data>
  <row>
    <v>0.0264</v>
    <v>1073655665.0000</v>  <!-- select this -->
    <v>1073749988.0000</v> 
  </row>
  <row>
    <v>0.0056</v>
    <v>1073655714.0000</v>  <!-- select this -->
    <v>1073751235.0000</v>
  </row>
  <row>
    <v>0.0052</v>
    <v>1073655812.0000</v>  <!-- select this -->
    <v>1073741221.0000</v>
  </row>
</data>

How do I select every n'th <v> element in each <row> using LINQ to XML.

Using XPath I'd just do /data/row/v[2] to select every 2nd <v> element but I can't seem to figure out how to do this using LINQ to XML.

+4  A: 
var qry = from row in dataNode.Elements("row")
           select row.Elements("v").ElementAt(1);

Should do? (untested)

Marc Gravell
Thanks...does exactly what I need.
Kev