Skip to main content
This article compares XmlEssentials with the System.Text.Xml API proposed in dotnet/runtime issue 125299. It goes through the proposal section by section and gives, for each proposed type and member, the XmlEssentials name and a status. It’s for readers who know the proposal and want to see how much of it this library implements, and where it differs. The comparison is against the proposal text as of November 2026 and the current XmlEssentials source. Each row was checked against the source.

How to read the tables

The proposal puts its types in System.Text.Xml and System.Text.Xml.Serialization. XmlEssentials uses CloudNimble.Text.Xml, CloudNimble.Text.Xml.Serialization, and CloudNimble.Text.Xml.Nodes. The proposal names its types with XmlData (XmlDataSerializer, Utf8XmlDataReader, XmlDataElementAttribute) to keep them apart from the types in System.Xml. XmlEssentials uses the shorter names without Data (XmlSerializer, Utf8XmlReader, XmlElementAttribute), which follow the System.Text.Json names with Json replaced by Xml. Several of those names are also names in System.Xml and System.Xml.Serialization, so a file that imports both namespaces needs an alias.

Summary

Enums

Reader options and state

The state holds more than JsonReaderState does. To resume inside a document, the reader needs the names of the open elements and the namespace declarations in scope, so CurrentState copies them. Only Options is public.

Reader

Utf8XmlDataReader is Utf8XmlReader, a ref struct.

Constructors

Properties

Methods

Writer options

Writer

Utf8XmlDataWriter is Utf8XmlWriter, a sealed class that implements IDisposable and IAsyncDisposable.

Serialization mapping attributes

The proposed attributes are in System.Text.Xml.Serialization and are named XmlData...Attribute. The XmlEssentials attributes are in CloudNimble.Text.Xml.Serialization. One default differs from what the proposal’s examples show. A collection member with no attribute is written as one element for each item, with no wrapper element. [XmlArray] adds the wrapper, as in the proposal’s Catalog example.

Serializer options

XmlDataSerializerOptions is XmlSerializerOptions. It’s a sealed class; the proposal doesn’t seal it.

Serializer

XmlDataSerializer is XmlSerializer, a static class. The type parameter is named TValue and the metadata parameter xmlTypeInfo. The overloads that take options use reflection and are marked with RequiresUnreferencedCode and RequiresDynamicCode. The overloads that take an XmlTypeInfo<T> or a context aren’t.

Custom converters

Source generation

Beyond the proposal

XmlEssentials also has these types, which the proposal doesn’t cover:

The proposal’s usage examples

The following sections run the examples from the proposal’s “API Usage” section with XmlEssentials. Each is a tested sample, and the output shown is the real output. View the complete sample on GitHub

Basic and span-based serialization

The proposal’s Person is the Contact class here, with [XmlRoot("Person")].
Program.cs
The code produces the following output:
Age comes before Name because Contact declares it first.

A reader over a sequence

Program.cs
The code produces the following output:

Partial reads with reader state

The proposal’s loop reads each chunk with a new reader. This version also carries over the bytes that the previous reader didn’t consume, which the proposal’s loop leaves out.
Program.cs
The code produces the following output:
BytesConsumed counts from the start of the current buffer, as it does in Utf8JsonReader.

Namespace-aware mapping

The proposal’s example uses XmlDataNamespaceDeclaration to choose the prefix addr, and XmlDataType to put the members of Address in a namespace. XmlDataType has no counterpart, so this mapping names the namespace on each member, and it leaves the prefix to the writer:
Employee.cs
Program.cs
The code produces the following output:
Every element has the same namespace as in the proposal’s expected output. The spelling is different: the address namespace is the default namespace of the Address element, where the proposal’s output declares the prefix addr on the root. To declare that prefix on the document element, add [XmlNamespaceDeclaration("addr", "http://example.com/address")] to Employee. Address comes before FullName because the class declares HomeAddress first.

Polymorphic collections

Product.cs
Program.cs
The code produces the following output:
The XML is the proposal’s expected output.

A reader with namespace comparison

Program.cs
The code produces the following output:
Apart from the type name, this is the proposal’s code.

A writer with namespaces

Program.cs
The code produces the following output:
The method calls are the proposal’s, and the XML is the proposal’s expected output.

Source generation

MigrationXmlContext.cs
Program.cs
The code produces the following output:
OrderLine has an [XmlAttribute("sku")] member and an [XmlText] member. The context exposes Default and one XmlTypeInfo<T> property for each listed type, as the proposal’s AppXmlContext.Default.Person does.

See also

Why XmlEssentials

The background to the proposal and to this library.

Coming from System.Text.Json

The same API, mapped from the System.Text.Json names.

Use Utf8XmlReader

The reader in detail.

Use Utf8XmlWriter

The writer in detail.

Use source generation

Contexts, modes, and Native AOT.

XML conformance

What the reader accepts and rejects.