<p>Say I have a xml document that looks like this</p>

<pre><code>&lt;foo&gt;
&lt;bar id="9" /&gt;
&lt;bar id="4" /&gt;
&lt;bar id="3" /&gt;
&lt;/foo&gt;
</code></pre>

<p>I would like to use linq to reset the id's to 0, 1 ,2.
What would be the easiest way to do this?</p>

<p>Thanks</p>

```
```
XElement xml = GetXml();
var i = 0;
foreach (var e in xml.Elements("bar"))
  e.SetAttributeValue("id", i++);
```
```