I am using HtmlAgilityPack
1.11.18 under .Net Core 2.2.
I want to remove all HTML attributes from <p>
nodes in an HTML fragment (not a complete document).
var htmlDoc = new HtmlDocument();
htmlDoc.LoadHtml(input);
var pNodes = htmlDoc.DocumentNode.SelectNodes("//p");
foreach (var node in pNodes)
{
node.Attributes.Remove();
}
return htmlDoc.Text;
This is not doing the trick, am I missing something? The method returns a string
which should be the fragment minus the attributes on all <p>
elements.
I realize you are not supposed to use RegEx to parse HTML but these are small fragments and I would prefer a RegEx method so I can remove the dependency on HtmlAgilityPack
, which I only brought in to handle this cleanly.