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?

Accepted Answer

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

foreach(var eachNode in HtmlDocument.DocumentNode.Descendants())
{
    eachNode.Attributes.RemoveAll();
}



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why