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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:15:31+00:00 2026-05-27T05:15:31+00:00

In an XML file such as : <Snippets> <Snippet name=abc> <SnippetCode> code goes here

  • 0

In an XML file such as :

<Snippets>
 <Snippet name="abc">
   <SnippetCode>
   code goes here
   </SnippetCode>
 </Snippet>

 <Snippet name="def">
   <SnippetCode>
   code goes here
   </SnippetCode>
 </Snippet>
</Snippets>

How can I remove an element when only its attribute name (like abc or def) is given?

  • 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-05-27T05:15:31+00:00Added an answer on May 27, 2026 at 5:15 am

    You could try something like this:

    string xmlInput = @"<Snippets>
     <Snippet name=""abc"">
       <SnippetCode>
       code goes here
       </SnippetCode>
     </Snippet>
    
     <Snippet name=""def"">
       <SnippetCode>
       code goes here
       </SnippetCode>
     </Snippet>
    </Snippets>";
    
    // create the XML, load the contents
    XmlDocument doc = new XmlDocument();
    doc.LoadXml(xmlInput);
    
    // find a node - here the one with name='abc'
    XmlNode node = doc.SelectSingleNode("/Snippets/Snippet[@name='abc']");
    
    // if found....
    if (node != null)
    {
       // get its parent node
       XmlNode parent = node.ParentNode;
    
       // remove the child node
       parent.RemoveChild(node);
    
       // verify the new XML structure
       string newXML = doc.OuterXml;
    
       // save to file or whatever....
       doc.Save(@"C:\temp\new.xml");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's my code: if(!$fileContents = file_get_contents($pathToXMLFile,true)) { throw new RuntimeException(Could not open .xml file);
I've got an xml file with such structure: <panel> <tr> <td> <element> ... smth
Can I read a XML file from remote server such as http://dealer.somedomain.com/data/inventory.xml I need
In my strings.xml file I have <string name=continue>Continue</string> I can't build my project because
Let's say I have an XML file such as this: <root> <level1 name=level1A> <level2
I have an XML file that starts like this: <Elements name=Entities xmlns=XS-GenerationToolElements> I'll have
I was given an .xml file that I needed to read into my code
Here's the XML file i'm working on: <list> <activity>swimming</activity> <activity>running</activity> <activity>soccer</activity> </list> The index.php,
I have two XML file sitemap.xml and mouse.xml which look like below.Here the thing
I am having a xml file as: <Order> <EP> <Name>Generation Date</Name> <Value>2009-08-04+05:30</Value> </EP> <EP>

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.