Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8200763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:33:41+00:00 2026-06-07T06:33:41+00:00

I have this result set that I load from an XML file calendarDocument =

  • 0

I have this result set that I load from an XML file

calendarDocument = XDocument.Load(@"C:\CalendarDB.xml");
IEnumerable<XElement> elements = from e in calendarDocument.Root.Elements("Session") select e;

not lets say I need to delete an element from the calendar file. Will this work?

elements.ToList().Remove(someElement);
calendarDocument.Save(@"C:\CalendarDB.xml");

what about this?

elements.ToList().Remove(someElement);
elements.Last().AddAfterSelf(anotherElement);
elements.Last().AddAfterSelf(yetAnotherElement);
element.ToList().Remove(anotherElement);
calendarDocument.Save(@"C:\CalendarDB.xml");

I have a feeling that every time I call Last() it returns a NEW result set DIRECTLY FROM THE CALENDAR FILE but when I call Remove() it does not remove the element from the file until I call Save() and if I dont call Save() immediately after each Remove() then the next call to Last() will return the same result set as before, still containing the deleted element.

Can someone tell me how this works please. Do I need to call Save() after Remove() each time in order to get the latest from Last()?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T06:33:44+00:00Added an answer on June 7, 2026 at 6:33 am

    You must not call ToList, that creates a copy of the result set and thus removing from it doesn’t affect the original document. To remove an element from the document, just call Remove on the element itself. For example:

    XDocument doc = XDocument.Parse("<root><child>a</child><child>b</child></root>");
    
    IEnumerable<XElement> children = doc.Root.Elements("child");
    
    XElement elementToRemove = children.Last();
    elementToRemove.Remove();
    
    XElement newLastElement = children.Last();
    Console.WriteLine(newLastElement.Value);
    

    The children variable holds enumerable, which is just a definition of a query. Every time you start your query from it, it will restart the query and thus get you the up-to-date results. But you mast start over from children.

    There’s no need to commit the changes in any way, they are applied immediately. Only if you want to write the modified document back to a file you will need to call Save on the document.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a query that creates a result set like this: Rank Name 1
I have this query which returns a result set with Date(column) as nvarchar datatype.
I have this expression: var result = from pav in ProductAttributes join id in
I have the following code that resides in my .js file //This is the
I've got a problem with the mysqli result set. I have a table that
I have written some code that pulls info from a plist file and does
We have some part of our application that need to load a large set
Given that I have this resultset structure (superfluous fields have been stripped) Id |
I have this public Result SomeMethod() { Popup popup = new Popup(); popup.Closed +=
I have got this result with the answer given by bluefeet Equipt BSL AQ

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.