SgmlSanitizer 1.0.0

There is a newer version of this package available.
See the version list below for details.
Install-Package SgmlSanitizer -Version 1.0.0
dotnet add package SgmlSanitizer --version 1.0.0
<PackageReference Include="SgmlSanitizer" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SgmlSanitizer --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SgmlSanitizer, 1.0.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install SgmlSanitizer as a Cake Addin
#addin nuget:?package=SgmlSanitizer&version=1.0.0

// Install SgmlSanitizer as a Cake Tool
#tool nuget:?package=SgmlSanitizer&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.


A sanitizer to remove elements and attributes from SGML based text files, such as HTML and XML. Note that this is a very simple implementation, but by using whitelists and a naïve URL detection implementation XSS may be prevented. Use at your own risk though.


To sanitize some simple HTML to remove all attributes and only keep the original HTML tag (this is inserted if not provided) and A tags:

string html = "<html><a href=\"https://url\">Keep me</a><p><a>Don't keep me</a></p></html>";

ListSanitiationHandler list = new ListSanitationHandler();

Sanitizer sanitizer = new Sanitizer();

string cleanHtml = sanitizer.Sanitize(html);

This outputs:

<html><a href="https://url">Keep me</a></html>

The list sanitation handler can be used to whitelist or blacklist elements, attributes and element specific attributes. The UrlAttributeHandler will remove attributes which contain '.' or '/', as the definition of an url is very broad.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.1 80 6/30/2021
1.0.0 146 6/27/2021