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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:51:27+00:00 2026-06-07T23:51:27+00:00

How do I remove the number node as well as its value from house?

  • 0

How do I remove the number node as well as its value from house?

Document:

<number>123456</number>
<house> <number> </number>Red</house>
<house> <number>12</number>Blue</house>
<number>345345</number>
etc...

Code:

private void getHouse(string houseHtml)
{
    HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument();

    htmlDoc.Load(new System.IO.StringReader(houseHtml));

    foreach (HtmlAgilityPack.HtmlNode house in htmlDoc.DocumentNode.SelectNodes("//house"))
    {
        MessageBox.Show(house.InnerText);
    }
}

Result:

 Red
12Blue

Required Result

Red
Blue

I have been trying to use:

house.RemoveChild(house.SelectSingleNode("//number"));

and some other combinations of this and run in to a “Node was not found in collection” or nothing will happen. It will also select the top most number, not the number inside the house tag.

  • 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-07T23:51:28+00:00Added an answer on June 7, 2026 at 11:51 pm

    Why don’t you remove the nodes directly?

    var numbers = htmlDoc.DocumentNode.SelectNodes("//house/number");
    if (numbers != null) {
        foreach(var node in number) 
            node.Remove();
    }
    

    Anyways, the reason your XPath is selecting all the nodes is because you need to give a path relative to the current node:

    house.SelectSingleNode("//number"); // wrong
    house.SelectSingleNode(".//number"); // right
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Javascript how would I remove any number of ../ from a relative path?
I am aiming for regex code to grab phone number and remove unneeded characters.
I want to remove digits from a float to have a fixed number of
is there any way to find it? for example: var number=5; $(#+>number).remove(); but I
I want to remove the decimal part of a number in a cell but
I would like to remove all trailing zeros without truncating or rounding the number
this works .. $(select[title='First Choice'] option[text='hello']).remove(); A number of variations of this does not
I want to remove any numbers from the end of a string, for example:
I want to keep only numbers and remove all characters from a variable. For
Currently I have the following code, working with Node.js, socket.io and Redis: var io

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.