NTokenizers 0.2.0-preview
See the version list below for details.
dotnet add package NTokenizers --version 0.2.0-preview
NuGet\Install-Package NTokenizers -Version 0.2.0-preview
<PackageReference Include="NTokenizers" Version="0.2.0-preview" />
<PackageVersion Include="NTokenizers" Version="0.2.0-preview" />
<PackageReference Include="NTokenizers" />
paket add NTokenizers --version 0.2.0-preview
#r "nuget: NTokenizers, 0.2.0-preview"
#:package NTokenizers@0.2.0-preview
#addin nuget:?package=NTokenizers&version=0.2.0-preview&prerelease
#tool nuget:?package=NTokenizers&version=0.2.0-preview&prerelease
NTokenizers
Collection of tokenizers for JSON, XML, SQL, Typescript, CSharp and Markup processing
Overview
NTokenizers is a .NET library written in C# that provides tokenizers for processing structured text formats like XML, JSON, and HTML. The Tokenize method is the core functionality that breaks down structured text into meaningful components (tokens) for processing. Its key feature is stream processing capability - it can handle data as it arrives in real-time, making it ideal for processing large files or streaming data without loading everything into memory at once.
These tokenizers are not validation-based and are primarily intended for prettifying, formatting, or visualizing structured text. They do not perform strict validation of the input format, so they may produce unexpected results when processing malformed or invalid XML, JSON, or HTML. Use them with caution when dealing with untrusted or poorly formatted input.
Example
Here's a simple example showing how to use the XML tokenizer:
```csharp
using System;
using System.IO.Pipes;
using System.Text;
using System.Threading.Tasks;
using NTokenizers;
using Spectre.Console;
class Program
{
static async Task Main()
{
string xml = """
<?xml version="1.0" encoding="utf-8"?>
<user id="4821" active="true">
<name>Laura Smith</name>
<addresses>
<address type="home">
<street>221B Baker Street</street>
<city>London</city>
</address>
</addresses>
</user>
""";
// Create connected streams
using var pipe = new AnonymousPipeServerStream(PipeDirection.Out);
using var reader = new AnonymousPipeClientStream(PipeDirection.In, pipe.ClientSafePipeHandle);
// Start slow writer
var writerTask = EmitSlowlyAsync(xml, pipe);
// Start parsing XML
XmlTokenizer.Parse(reader, onToken: token =>
{
var value = Markup.Escape(token.Value);
var colored = token.TokenType switch
{
XmlTokenType.ElementName => new Markup($"[blue]{value}[/]"),
XmlTokenType.EndElement => new Markup($"[blue]{value}[/]"),
XmlTokenType.OpeningAngleBracket => new Markup($"[yellow]{value}[/]"),
XmlTokenType.ClosingAngleBracket => new Markup($"[yellow]{value}[/]"),
XmlTokenType.SelfClosingSlash => new Markup($"[yellow]{value}[/]"),
XmlTokenType.AttributeName => new Markup($"[cyan]{value}[/]"),
XmlTokenType.AttributeEquals => new Markup($"[yellow]{value}[/]"),
XmlTokenType.AttributeQuote => new Markup($"[grey]{value}[/]"),
XmlTokenType.AttributeValue => new Markup($"[green]{value}[/]"),
XmlTokenType.Text => new Markup($"[white]{value}[/]"),
XmlTokenType.Whitespace => new Markup($"[grey]{value}[/]"),
XmlTokenType.Comment => new Markup($"[grey]{value}[/]"),
XmlTokenType.CData => new Markup($"[magenta]{value}[/]"),
XmlTokenType.DocumentTypeDeclaration => new Markup($"[orange1]{value}[/]"),
XmlTokenType.ProcessingInstruction => new Markup($"[orange1]{value}[/]"),
_ => new Markup(value)
};
AnsiConsole.Write(colored);
});
await writerTask;
Console.WriteLine();
Console.WriteLine("Done.");
}
static async Task EmitSlowlyAsync(string xml, Stream output)
{
var rng = new Random();
byte[] bytes = Encoding.UTF8.GetBytes(xml);
foreach (var b in bytes)
{
await output.WriteAsync(new[] { b }.AsMemory(0, 1));
await output.FlushAsync();
await Task.Delay(rng.Next(10, 60));
}
output.Close(); // EOF
}
}
This gives the following output:
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
This package has no dependencies.
NuGet packages (2)
Showing the top 2 NuGet packages that depend on NTokenizers:
| Package | Downloads |
|---|---|
|
NTokenizers.Extensions.Spectre.Console
Stream-capable Spectre.Console rendering extensions for NTokenizers (XML, JSON, Markdown, TypeScript, CSS, HTML, C#, SQL, TOML, C, C++, Go, Java, Kotlin, Python, Rust and Swift), Style-rich console syntax highlighting |
|
|
Jumbee.Console
A .NET library for retained-mode terminal user interfaces (TUIs) that focuses on performance and ease-of-use. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 6.2.0 | 105 | 7/12/2026 |
| 6.1.1 | 434 | 6/3/2026 |
| 6.1.0 | 116 | 5/31/2026 |
| 6.0.1 | 109 | 5/31/2026 |
| 6.0.0 | 174 | 5/30/2026 |
| 5.0.0 | 147 | 5/26/2026 |
| 4.0.0 | 2,095 | 1/14/2026 |
| 3.0.0 | 197 | 1/4/2026 |
| 2.2.0 | 139 | 1/3/2026 |
| 2.1.0 | 358 | 12/11/2025 |
| 2.0.0 | 463 | 12/11/2025 |
| 1.0.1 | 485 | 12/9/2025 |
| 1.0.0 | 438 | 12/8/2025 |
| 0.8.0-preview | 216 | 12/6/2025 |
| 0.7.0-preview | 163 | 12/6/2025 |
| 0.6.0-preview | 762 | 12/3/2025 |
| 0.5.0-preview | 710 | 12/3/2025 |
| 0.4.0-preview | 706 | 12/2/2025 |
| 0.3.0-preview | 738 | 12/2/2025 |
| 0.2.0-preview | 225 | 11/27/2025 |
Added CSharp, Typescript, Sql and Markup stream tokenizers.