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 7905275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T10:24:35+00:00 2026-06-03T10:24:35+00:00

The following fragment deletes DpsRecord elements which contain Name element which value contains JOSE.

  • 0

The following fragment deletes “DpsRecord” elements which contain “Name” element which value contains “JOSE”. However, I don’t understand how after applying Linq query to root and getting dpsRecords ( left side of query ) and then removing in dpsRecords, elements are also removed in root.

XElement root = XElement.Load("input.xml");
IEnumerable<XElement> dpsRecords = from elem in
                        root.Elements("DpsRecord")
                        where (((string)elem.Element("Name")).Contains("JOSE"))              
                        select elem;
foreach (XElement elem in dpsRecords)
{
   elem.Remove();
}
root.Save("output.xml"); 
  • 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-03T10:24:37+00:00Added an answer on June 3, 2026 at 10:24 am

    Well the Remove method http://msdn.microsoft.com/en-us/library/system.xml.linq.xnode.remove.aspx removes the node it is called on from its parent node.

    Also take note that you don’t need the foreach, you can do dspRecords.Remove().

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

Sidebar

Related Questions

I have a schema fragment that looks like <xs:element name=dataValue> <xs:complexType> <xs:sequence> <xs:element name=value
I have the following fragment of XAML: <ComboBox Name=comboBox1 IsEditable=True Text=test TextBlock.TextAlignment=Right /> How
I have the following XUL fragment, which works fine, but puts a 1 pixel
Consider the following xml fragment: <Obj> <Name><![CDATA[SomeText]]></Name> </Obj> How do I retrieve the SomeText
I have the following code fragment in an object initializer. However, the third line
I have the following XML fragment: ... <Setting name=HOST1>server1</Setting> <Setting name=HOST2>server2</Setting> <Setting name=HOST3>server4</Setting> <Setting
I'm using the following code fragment to stop a service. However, both the Console.Writeline
I trying to parse the message element out of the following XML fragment using
Given the following fragment of html: <fieldset> <legend>My Legend</legend> <p>Some text</p> Text to capture
I have to following code fragment, and no matter what I set the font-size

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.