System.Xml, and it’s ready for production today.
The System.Text.Json equivalent for XML that .NET developers have been begging for!
3.0× faster on average
Than
System.Xml, across 67 comparisons. The range is 1.1× to 19×, with one exception.85% less memory
On average. 32 of the 67 comparisons allocate 0 bytes.
104 bytes
To parse a document of any size into a DOM.
System.Xml needs 127 KB to 709 KB for the same files.Get started in five minutes
Install the package and read, write, and serialize your first document.
See the numbers
3.0× faster than
System.Xml on average, with 85% less memory allocated.Everything System.Text.Json taught you, now for XML
If you know System.Text.Json, you already know XmlEssentials. The types, the method names, and the patterns carry straight over.
Coming from JSON? Start with what’s different about XML.
Next to the code you have today
Hover over or select what you use now to see the same task in XmlEssentials, side by side, and what changes when you move.Lightning fast, and light on memory
XmlEssentials reads and writes UTF-8 directly. There’s no transcoding to UTF-16, no string for every name, and no object for every node. Across 67 like-for-like benchmarks againstSystem.Xml, it’s 3.0× faster on average and allocates 85% less memory.
Up to 19× faster
Reading a value takes 56 ns.
System.Xml takes 1,068 ns.3.1× to 3.4× faster parsing
Real documents into a DOM, in 104 bytes instead of hundreds of kilobytes.
Zero-allocation writes
Serialize into a buffer you own and the library allocates 0 bytes.
System.Xml does.
Built for .NET in 2027 and beyond
XmlEssentials targets .NET 10 and .NET 11 and nothing older. There’s no .NET Framework or .NET Standard build to hold it back, so the API uses the language and the runtime as they are today.Source generation
List your types on a context and a Roslyn incremental generator writes their metadata at build time. The serializer uses no reflection and generates no code at run time.
Native AOT and trimming
Publish with
PublishAot and it works. A test in the suite publishes a real app with Native AOT and runs it.Safe by default
No DTDs, no external entities, and limits on depth and size. Billion-laughs and XXE attacks have nothing to attack.
Streaming and async
Stream, PipeReader and PipeWriter, and IAsyncEnumerable<T>, each with a CancellationToken, so you can read a huge feed one item at a time.Spans and buffers
ReadOnlySpan<byte>, ReadOnlySequence<byte>, and IBufferWriter<byte> throughout. The reader is a ref struct that lives on the stack.Your types, as you write them
Positional records, constructors,
init and required members, internal types, dictionaries, and polymorphism. No public parameterless constructor needed.XML 1.0 and XML 1.1
Both versions of the specification, plus Namespaces in XML, verified against the W3C conformance suite.
System.Xml never implemented XML 1.1.No System.Xml
One package with no dependency on the old XML stack, so nothing of it lands in your trimmed app.
Generic attributes
[XmlSerializable<Person>], [XmlDerivedType<Dog>], [XmlConverter<MoneyConverter>]. The compiler checks the type, and there’s no typeof to get wrong.Closed types
On .NET 11, declare a hierarchy
closed and the serializer takes its derived types from the compiler. You register nothing.Today's value types
DateOnly, TimeOnly, Int128, UInt128, and Half work out of the box, next to the types you’ve always had.Classes from your schema (preview)
Add an
.xsd file to your project and get types and a serialization context generated for you. In preview.init, required, and non-public members through [UnsafeAccessor], not reflection, and the reader and writer are built on SearchValues<T>, IUtf8SpanFormattable, and frozen collections. As .NET adds to the language and the runtime, XmlEssentials is free to follow.
How it compares
XmlEssentials is deliberately not a drop-in copy of
System.Xml. It leaves out DTDs, XPath, XSLT, and encodings other than UTF-8. If you need those, keep System.Xml for that part of your app. See XML conformance for the exact boundary.
Tested like a platform library
- 100% line coverage and 100% branch coverage, enforced on every build.
- Thousands of tests, run on both .NET 10 and .NET 11.
- 283 cases from the W3C XML Conformance Test Suite, plus real documents from other parsers’ test suites.
- Documents are read split at every byte offset, so XML that arrives in pieces reads the same as XML that arrives whole.
- Every sample in these docs is compiled and tested. If the docs show output, a test asserts it.
Dive in
Quickstart
Install and write your first XML.
Why XmlEssentials?
The story behind the library.
Migrate
Move over from
System.Xml.CloudNimble/XmlEssentials
Loading repository data...