How to remove all attributes in HTML tags

c# html-agility-pack uwp

Question

I would like to remove all attributes from HTML tags, for example

<div class="" style="" >

I have attempted this using HTMLAgilityPack however it seems that SelectNodes will not work

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

How would I make this work in C# for UWP?

1
3
6/8/2016 12:21:02 PM

Accepted Answer

As an alternative to SelectNodes("//*"), you can use Descendants() which should return the same result :

foreach(var eachNode in HtmlDocument.DocumentNode.Descendants().Where(x => x.NodeType == HtmlNodeType.Element))
{
    eachNode.Attributes.RemoveAll();
}
0
7/16/2019 8:43:52 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow