Linq to XML - update/alter the nodes of an XML Document
Posted
by knox
on Stack Overflow
See other posts from Stack Overflow
or by knox
Published on 2008-12-01T17:13:41Z
Indexed on
2010/05/17
7:10 UTC
Read the original article
Hit count: 1094
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>
© Stack Overflow or respective owner