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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:52:33+00:00 2026-06-05T22:52:33+00:00

I tried looking this up on here but couldnt find a proper answer. I

  • 0

I tried looking this up on here but couldnt find a proper answer. I have a XML string which has a bunch of nodes.
I want to extract only a couple of nodes from this string and append it with a new root element and return it.

I know how to do this by loading this onto an XMLDocument and selecting nodes. Is there a better way of doing this using an XpathNavigator or XmlReader?

This is my String

<root>
  <node1/>
  <node2/>
  <node3/>
  <node4/>
  <node5>
</root>

I want my output string to be

<root>
   <node3/>
   <node4/>
 </root>

Has to be done in an efficient manner.

  • 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-05T22:52:34+00:00Added an answer on June 5, 2026 at 10:52 pm

    For the sake of simplicity, I would use XDocument.Parse(). And manipulate the DOM through the provided functions. Since the XML is provided as a string, probably small, I’m willing to bet that you will not see complexity problems.

    If there are a lot of nodes to remove, I suggest you use a list of XPath strings. Then for each string, you can use doc.XPathSelectElements() to find all the elements and call remove() on each one. The resulting XDocument will have just the remaining nodes.

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

Sidebar

Related Questions

I have been looking around for an answer to this, but couldn't really find
First post here, I have tried searching but couldn't find what I'm looking for
I have been looking around for this but couldn't find an answer anywhere, so
I've tried to find a way to do this, but without success. I'm looking
I tried looking up other issues but couldn't find anything to match so here
This may have been asked in the past but I couldnt find a suitable
I have tried looking though several of the already asked question about this topic
I've tried looking at similar problems, but could not easily find one that helped
i have tried looking online but had no luck, How i could delete all
I have tried looking all over the net for some help, and couldn't find

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.