Skip to main content
Home Forums Silverlight Programming Programming with .NET - General How to use XDocument to add, update, delete the xml node information?
2 replies. Latest Post by spiderman110 on November 4, 2009.
(0)
spiderma...
Member
225 points
282 Posts
11-02-2009 3:37 AM |
Hi, allI have a xml string like below:<Product> <A id="001"/> <B id="002"/> <C id="003"/> <D id="004"> <D1 id="0041" /> <D2 id="0042" /> </D> <E id="005"/></Product>ex, I could add D3 node in D node or delete D1 node from D node or modify the id "0042" to "0044" of D2 nodeIn a word, I want to handle somthing on D node.
If D3 node is added, I want to return a string value like this:
<Product> <A id="001"/> <B id="002"/> <C id="003"/> <D id="004"> <D1 id="0041" /> <D2 id="0042" />
<D3 id="0043" /> </D> <E id="005"/></Product>
I don:t konw XDocument could implement this or not. or other class could do this.Any Suggestions?Thanks for your all advance!!!
Pravinku...
Contributor
4300 points
708 Posts
11-03-2009 6:23 AM |
Hi,
Check the articals below. It may help you out for Add/Delete/Modify xml nodes.
http://www.programminghelp.com/programming/dotnet/using-linq-to-xml-to-add-data-to-xml-file-in-c/
http://www.c-sharpcorner.com/UploadFile/dhananjaycoder/creatingsavingxmltreelinq07292009084107AM/creatingsavingxmltreelinq.aspx
Check the samples for LINQ-To-XML
http://msdn.microsoft.com/en-us/vbasic/bb688087.aspx
Thanks,
Pravin
"Please mark as answered, if this answers your question"
11-04-2009 10:43 PM |
Thank you very much.I just find the way how to add, update, delete xml file using XDocumentThere are sample source.Hope it is useful to others.XDocument xd = XDocument.Parse(xmlString);// add child node of appSettingsxd.Root.Element("appSettings").Add(new XElement("add", new XAttribute("key", "001"), new XAttribute("value", "Value001")));// delete child node of appSettingsxd.Root.Element("appSettings").RemoveNodes();