如何删除HTML标记中的所有属性

时间:2016-06-08 11:17:31

标签: c# uwp html-agility-pack

我想从HTML标记中删除所有属性,例如

<div class="" style="" >

我尝试使用HTMLAgilityPack,但似乎SelectNodes无法正常工作

foreach(var eachNode in HtmlDocument.DocumentNode.SelectNodes("//*"))
{
   eachNode.Attributes.RemoveAll();
}

我如何在C#中为UWP做这项工作?

1 个答案:

答案 0 :(得分:0)

作为SelectNodes("//*")的替代方案,您可以使用Descendants(),它应返回相同的结果:

foreach(var eachNode in HtmlDocument.DocumentNode.Descendants())
{
    eachNode.Attributes.RemoveAll();
}
相关问题