I can select the first customer node and change its company name with the code below.
But how do I select customer node where ID=2?
XDocument xml
Assuming the ID is unique:
var result = xmldoc.Element("Customers") .Elements("Customer") .Single(x => (int?)x.Attribute("ID") == 2);
You could also use First, FirstOrDefault, SingleOrDefault or Where, instead of Single for different circumstances.
First
FirstOrDefault
SingleOrDefault
Where
Single