tags:

views:

400

answers:

4
A: 

Usually, I solve this kind of issue via File I/O and RegEx (which is not advised at all to deal with xml/html documents, as the commentators dutifully noted).

That said, if you want to do it properly, I'm pretty sure there's a DOM object in C#.

This one seems to support XPath request, which is pretty handy.

Vinzz
http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags
SLaks
The div might have embedded divs. So how will you understand where the div ends?
StuffHappens
Indeed, that's why I talked about a proper way to do such things (like Agility pack)
Vinzz
+9  A: 

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.

Henk Holterman
+1, beat me to it :)
Adam Neal
+1  A: 

You're looking for the HTML Agility Pack.

SLaks
+1  A: 

To solve your problem, you can use LINQ:

foreach(var node in doc.DocumentNode
            .Descendants("div")
            .Where(d => d.GetAttributeValue("class", "").IndexOf("NavContent") >= 0)
            .ToArray())
    node.Remove();
SLaks