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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:12:59+00:00 2026-05-14T00:12:59+00:00

I have a html document and I want to delete all the divs of

  • 0

I have a html document and I want to delete all the divs of certain class (with all the content). What is the simplest way to do it?

Thank you for your help.

UPDATED:

I tried out Html Agility Pack as you adviced, but I failed to reach the aim.
I have the following code

        static void Main()
        {
            HtmlDocument document = new HtmlDocument();
            document.Load(FileName);
            HtmlNode node = document.DocumentNode;
            HandleNode(node);
        }

    private static void HandleNode(HtmlNode node)
    {
        while (node != null)
        {
            if (node.Name == "div")
            {
                var attribute = node.Attributes.Where(x => x.Name == "class" && x.Value == "NavContent");
                if (attribute.Any())
                    node.Remove();
            }
            foreach (var childNode in node.ChildNodes)
            {
                HandleNode(childNode);
            }
        }

    }


But it doesn't do want I want. The recursion never ends and the node name is always comment.
Here's the htmp-document I'm trying to parse: http://en.wiktionary.org/wiki/work
Is there a good example how to work with Html Agility Pack?
What's wrong with this piece of code?

  • 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-14T00:12:59+00:00Added an answer on May 14, 2026 at 12:12 am

    It depends on how complex your HTML is, but you will probably need the Agility Pack library.

    Re the Update:

    HandleNode() contains a while(node != null) loop but never assigns to node. I would change that to an if(...) to start with.

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

Sidebar

Related Questions

I have an HTML document as a string I want to search for a
I have a HTML document with the below setup: <div class=main-div style=padding: 5px; border:
I have a HTML document with the a table which I want to replace,
I am facing the following problem: I have a HTML document where I want
I have HTML something like this: <table> <tr> <td><div class='record'>Record Link</div></td> <td><div class='delete' style='display:none;'>Delete
I have a HTML document like below: <td> <div class="commentLink"> <a href="javascript:ShowBox()">Show</a> </div> <div
I have the following code $(document).ready(function(){ // class exists if($('.delete').length) { // add click
I have a HTML document that I want to remove specific tags from, identified
I have an html document that I saved as a .txt file. I want
I have these pieces of HTML: <li class=icon iconDelete><a href=/projects/delete/{id}/ title=Delete this test case.></a></li>

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.