I'm trying to remove any duplicate or more occurrences of any < br > tags in my html document. This is what I've come up with so far (really stupid code):
HtmlNodeCollection elements = nodeCollection.ElementAt(0)
.SelectNodes("//br");
if (elements != null)
{
foreach (HtmlNode element in elements)
{
if (element.Name == "br")
{
bool iterate = true;
while(iterate == true)
{
iterate = removeChainElements(element);
}
}
}
}
private bool removeChainElements(HtmlNode element)
{
if (element.NextSibling != null && element.NextSibling.Name == "br")
{
element.NextSibling.Remove();
}
if (element.NextSibling != null && element.NextSibling.Name == "br")
return true;
else
return false;
}
}
The code does find the br tags but it doesn't remove any elements at all.