Linq to XML - update/alter the nodes of an XML Document
- by knox
Hello!
If got 2 Questions:
1.
I've sarted working around with Linq to XML and i'm wondering if it is possible to change a XML document via Linq. I mean, is there someting like
XDocument xmlDoc = XDocument.Load("sample.xml");
update item in xmlDoc.Descendants("item")
where (int)item .Attribute("id") == id
...
2.
I already know how to create and add a new XMLElement by simply using
xmlDoc.Element("items").Add(new XElement(......);
but how can i remove a single entry.
XML sample data:
<items>
<item id="1" name="sample1" info="sample1 info" web="" />
<item id="2" name="sample2" info="sample2 info" web="" />
</itmes>