C#: delete an element from xml -


i writing , reading xml file c# winfroms level. additionally want have function delete element given content. xml format:

<libraryimages>     <imagelink>*link1*</imagelink>     <imagelink>*link2*</imagelink> </libraryimages> 

function body:

system.xml.linq.xdocument xdoc = system.xml.linq.xdocument.load("xmldata.xml");             xdoc.root.elements("imagelink").select(el => el).where(el => el.value == pathtoremove).tolist().foreach(el => el.remove()); 

as 'pathtoremove' parameter pass link1 example. thing - doesn't remove element xml - after restart application content of library previously, if hadn't removed item. why doesn't work? i've browsed through many of stackoverflow questions, though i've found nothing.

you should update xml file after in-memory manipulations:

// read file disc , build in-memory representation of xml var xdoc = xdocument.load("xmldata.xml");  // modify in-memory representation xdoc.root.elements("imagelink").where(el => el.value == pathtoremove).remove();  // save modified representation disck xdoc.save("xmldata.xml"); 

Comments

Popular posts from this blog

php - Displaying JSON data posts for blog using just the post id -

google bigquery - Delta between query execution time and Java query call to finish -

node.js - How to check multiple conditions to be true or false using protractor ,so that it helps in validating input before click -