html agility pack remove children

谁说我不能喝 提交于 2019-12-02 07:19:28
bobince

bodyNode.RemoveChild(functionBarNode,false);

But functionBarNode is not a child of bodyNode.

How about functionBarNode.ParentNode.RemoveChild(functionBarNode, false)? (And forget the bit about finding bodyNode.)

You can simply call:

var documentNode = document.DocumentNode;
var functionBarNode = documentNode.SelectSingleNode("//div[@id='functionBar']");
functionBarNode.Remove();

It is much simpler, and does the same as:

functionBarNode.ParentNode.RemoveChild(functionBarNode, false);
Aaron Gibson

This will work for multiple:

HtmlDocument d = this.Download(string.Format(validatorUrl, Url));
foreach (var toGo in QuerySelectorAll(d.DocumentNode, "p[class=helpwanted]").ToList())
{
   toGo.Remove();
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!