c# - LINQ - Remove elements based on value -


here xml file looks like:

<?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> </synctimes> 

i'm trying create method remove old sync times. attempt:

    public void deletearchivedsyncs(int months)     {         var xelement = (from element in xmldocobject.elements("synctimes").elements("lastsynctime")                         convert.todatetime(element.attribute("synctime").value) < datetime.now.addhours(-months)                         select element);         xelement.remove();     } 

currently i'm running method 0 see if runs.

this i'm getting:

enter image description here

to me looks here resulting in null exception:

element.attribute("synctime").value 

but don't understand based on looking @ xml why occur.

<synctime> not attribute - element. therefore expression element.attribute("synctime") returns null, , attempting access value throws null reference exception.


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 -