我的xml文件看起来像这样..
<RecentInformation>
<User Id="99">
<Customers>
<Customer>
<CustomerId>7</CustomerId>
<Date>1/20/2010</Date>
</Customer>
<Customer>
<CustomerId>67</CustomerId>
<Date>1/20/2010</Date>
</Customer>
</Customers>
<Suppliers>
<Supplier>
<SupplierId>11619</SupplierId>
<Date>1/20/2010</Date>
</Supplier>
<Supplier>
<SupplierId>16274</SupplierId>
<Date>1/20/2011</Date>
</Supplier>
</Suppliers>
<Enquiries>
<Enquiry>
<EnquiryId>136202</EnquiryId>
<Date>1/20/2010</Date>
</Enquiry>
<Enquiry>
<EnquiryId>134507</EnquiryId>
<Date>1/20/2011</Date>
</Enquiry>
</Enquiries>
<Quotes>
<Quote>
<QuoteId>34008</QuoteId>
<Date>1/20/2010</Date>
</Quote>
<Quote>
<QuoteId>37356</QuoteId>
<Date>1/20/2011</Date>
</Quote>
</Quotes>
<Bookings>
<Booking>
<BookingId>3070</BookingId>
<Date>1/20/2011</Date>
</Booking>
<Booking>
<BookingId>3251</BookingId>
<Date>1/20/2011</Date>
</Booking>
</Bookings>
</User>
</RecentInformation>
我想删除所有应该少于15天的节点。
我正在使用此代码,但它对我不起作用..
xdoc.Descendants("User").Descendants().Descendants().Where(x => DateTime.Parse(x.Element("Date").Value) < date)
.Remove();
任何想法?
答案 0 :(得分:1)
这是你固定的行
xdoc.Descendants("Date").Where(x => DateTime.Parse(x.Value) < date).Select(x=>x.Parent).Remove();