Sometimes you may have to sanitize a piece of HTML before storing or displaying it.
Say you have the following snippet and you want to
- Remove the
itemtypeattributes from the first
- Drop completely the
You might be tempted to reach for
Regex.Replace, but that would be
a terrible idea
Instead use HtmlAgilityPack, which provides the ability to load, examine, and modify HTML documents and snippets.
This example demonstrates how to remove attributes and nodes from an HTML snippet.