0

I have xml file that looks like this..

<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>

I want to remove all the nodes that should be less then say 15 days old.

I am using this code but it is not working for me..

xdoc.Descendants("User").Descendants().Descendants().Where(x => DateTime.Parse(x.Element("Date").Value) < date)
                            .Remove();

any idea??

2
  • Describe "not working" ? Commented Jan 20, 2011 at 15:15
  • exception thrown object reference not..... Commented Jan 20, 2011 at 15:18

1 Answer 1

1

This is your line fixed

xdoc.Descendants("Date").Where(x => DateTime.Parse(x.Value) < date).Select(x=>x.Parent).Remove();
Sign up to request clarification or add additional context in comments.

2 Comments

Sorry for late reply Dario. This code is working perfect for me. Thanx you so much you and all the guys who gives the answer.
perhaps Naveed Anjum is new to SO hence he dont know he have to mark it as answered. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.