paquete de agilidad html quitar niños
Tengo dificultades para intentar eliminar un div con una ID particular y sus hijos usando el paquete de agilidad HTML. Estoy seguro de que me estoy perdiendo una opción de configuración, pero es viernes y estoy luchando.
El HTML simplificado se ejecuta:
<html><head></head><body><div id='wrapper'><div id='functionBar'><div id='search'></div></div></div></body></html>
Esto es todo lo que tengo. El error lanzado por el paquete de agilidad muestra que no puede encontrar una estructura div:
<div id='functionBar'></div>
Aquí está el código hasta ahora (tomado de Stackoverflow ...)
HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument();
// There are various options, set as needed
//htmlDoc.OptionFixNestedTags = true;
// filePath is a path to a file containing the html
htmlDoc.LoadHtml(Html);
string output = string.Empty;
// ParseErrors is an ArrayList containing any errors from the Load statement
if (htmlDoc.ParseErrors != null && htmlDoc.ParseErrors.Count > 0)
{
// Handle any parse errors as required
}
else
{
if (htmlDoc.DocumentNode != null)
{
HtmlAgilityPack.HtmlNode bodyNode = htmlDoc.DocumentNode.SelectSingleNode("//body");
if (bodyNode != null)
{
HtmlAgilityPack.HtmlNode functionBarNode = bodyNode.SelectSingleNode ("//div[@id='functionBar']");
bodyNode.RemoveChild(functionBarNode,false);
output = bodyNode.InnerHtml;
}
}
}