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

  • Home
  • SEARCH
  • 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 8638181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:39:44+00:00 2026-06-12T10:39:44+00:00

I am New To C# I have problem… I want to delete selected node

  • 0

I am New To C# I have problem…
I want to delete selected node from My XMl File
Here I just tried with this code but I didn’t get please can any one help in that

private void btnDelete_Click(object sender, EventArgs e)
{
    xdoc.Load(strFilename);
    string Xpath = string.Format("root/{0}/{1}",_strProCat,_strProdType);
    xdoc.SelectSingleNode(Xpath).RemoveAll();

    xdoc.Save(strFilename);
    MessageBox.Show("Deleted Successfully");
}

Here My Xml File

<root>
  <product category="Soaps">
   <product type="Washing">
     <product name="Rin">
      <Id>100</Id>
      <AvailProducts>30</AvailProducts>
      <Cost>20.00</Cost>
   </product>
  <product name="Tide">
    <Id>101</Id>
    <AvailProducts>30</AvailProducts>
    <Cost>15.00</Cost>
  </product>
 </product>
</product>
</root>

Just I want to delete Node which product name="Tide"

  • 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-12T10:39:46+00:00Added an answer on June 12, 2026 at 10:39 am

    You can simple use the below code:

    private void btnDelete_Click(object sender, EventArgs e)
    {
        var xDoc = XDocument.Load(strFilename);
    
        foreach (var elem in xDoc.Document.Descendants("product"))
        {
            foreach (var attr in elem.Attributes("name"))
            {
                if (attr.Value.Equals("Tide"))
                    elem.RemoveAll();
            }
        }
    
        xDoc.Save(destinationFilename);
        MessageBox.Show("Deleted Successfully");
    }
    

    Happy Coding…

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

Sidebar

Related Questions

i have problem with simpleXml and adding new items. This is my xml: <?xml
I have problem with adding new node (with namespace) to my xml document which
I have problem creating new instance of excel 2007 using VBA (from Access 2002).
I have problem with WPF - I'm quiet new in this smart technology. So
I have problem. This is my code: var method = new DynamicMethod(dummy, null, Type.EmptyTypes);
I'm new here and have a problem. I am having to pick up C#
I am new in C and I have problem with compiling this code. #include
I have problem when creating a file in encoding 'utf-8' and reading it from
I have new problem with query: I want to update column 'column' depending on
I have problem with rename file. I need new file name be cyrillic but,

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.