I\'ve got 2 Questions:
1. I\'ve sarted working around with Linq to XML and i\'m wondering if it is possible to change an XML document via Linq. I mean, is there some
The answers are in this thread...you just have to do a lot of sorting to find them, so I've done the work of compliling them for you:
Now if you're reading this thread, you probably want to know HOW to edit elements. There are two different ways that data is stored in xml, e.g.:
another value
To edit the value of an attribute, knox answered his own question:
d.Descendants("record").Where(x => x.Attribute("id").Value == "2").Single().SetAttributeValue("info", "new sample info");
In other words, get the XElement that you want to alter, and call element.SetAttributeValue("AttributeName", "new value for the attribute")
if you want to edit the value or contents of a tag, then Ajay answered it (if you dig through all his code):
persondata.Element("City").Value = txtCity.Text;
Or, in other words, once you have the XElement you're after, just use .Value and assign away.
Remember that after you perform any of these modifications on the elements in memory, you've got to call .Save() on the XDocument if you want to persist those changes to disk.