c# - LINQ - Specified elements not being removed from XML file -


i have xml file:

<?xml version="1.0" encoding="utf-8" standalone="yes"?> <!--qtabs data storage--> <synctimes>   <lastsynctime>     <id>1</id>     <synctime>3/31/2015 2:03:28 pm</synctime>   </lastsynctime>   <lastsynctime>     <id>2</id>     <synctime>3/31/2015 2:14:24 pm</synctime>   </lastsynctime>   <lastsynctime>     <id>3</id>     <synctime>3/31/2015 2:14:25 pm</synctime>   </lastsynctime>   <lastsynctime>     <id>4</id>     <synctime>3/31/2015 2:14:26 pm</synctime>   </lastsynctime> </synctimes> 

all of above times earlier today want delete lastsynctime records before current time (datetime.now):

public async void deletearchivedsyncs() {     var xelement = (from element in xmldocobject.elements("lastsynctime")                     convert.todatetime(element.element("synctime").value) < datetime.now                     select element);     xelement.remove();     storagefile = await storagefolder.getfileasync(settings.xmlfile);     using (stream filestream = await storagefile.openstreamforwriteasync())     {         xmldocobject.save(filestream);     } } 

this being run not effect xml page. desired elements not being removed. doing wrong?

this issue here appears way delete child, have parent deletion, in:

class program {     public static void main(params string[] args)     {         // test.xml contains ops example content.         var xdoc = xdocument.load(@"c:\temp\test.xml");          xdoc.descendants("lastsynctime")            .where(e => convert.todatetime(e.element("synctime").value) < datetime.now)            .remove();         console.writeline(xdoc);         xdoc.save(@"c:\temp\test_filtered.xml");     } } 

this generates following output:

<?xml version="1.0" encoding="utf-8" standalone="yes"?> <!--qtabs data storage--> <synctimes /> 

i.e. empty root, expected, given dates smaller datetime.now.


Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -