Soenneker.Utils.Xml 11.0.1194

Prefix Reserved
dotnet add package Soenneker.Utils.Xml --version 11.0.1194
                    
NuGet\Install-Package Soenneker.Utils.Xml -Version 11.0.1194
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Soenneker.Utils.Xml" Version="11.0.1194" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.Utils.Xml" Version="11.0.1194" />
                    
Directory.Packages.props
<PackageReference Include="Soenneker.Utils.Xml" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Soenneker.Utils.Xml --version 11.0.1194
                    
#r "nuget: Soenneker.Utils.Xml, 11.0.1194"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Soenneker.Utils.Xml@11.0.1194
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Soenneker.Utils.Xml&version=11.0.1194
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.Utils.Xml&version=11.0.1194
                    
Install as a Cake Tool

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

alternate text is missing from this package README image Soenneker.Utils.Xml

Cached XmlSerializer helpers for strings and streams, with secure reader defaults and optional removal of nil elements.

Installation

dotnet add package Soenneker.Utils.Xml

Serialize to a string

using Soenneker.Utils.Xml;

string? xml = XmlUtil.Serialize(order);

Serialize<T> returns null when the object is null. By default it uses UTF-8, suppresses the serializer's standard namespace declarations, and removes elements marked xsi:nil="true", xsi:nil="1", or the equivalent unqualified nil attribute.

Removing nil elements is a structural transformation: the entire marked element is removed, not converted to an empty element. It requires an XDocument parse-and-save pass. Set removeXsiNilElements: false for direct streaming and standard XmlSerializer nil output.

string? xml = XmlUtil.Serialize(
    order,
    encoding: Encoding.UTF8,
    removeNamespaces: false,
    removeXsiNilElements: false);

removeNamespaces controls the namespace declarations supplied to XmlSerializer; it does not strip namespaces required by attributes or type metadata.

Serialize to a stream

await using var destination = File.Create("order.xml");

XmlUtil.Serialize(
    order,
    destination,
    leaveOpen: true);

Serialization begins at the stream's current position. The utility does not rewind or truncate an existing destination. With the default leaveOpen: false, the destination is closed after a non-null object is serialized. A null object is a no-op.

Pass an IMemoryStreamUtil to use its pooled stream for temporary serialization. The caller retains ownership of the utility; temporary streams obtained from it are disposed by XmlUtil.

Deserialize

Order? fromString = XmlUtil.Deserialize<Order>(xml);
Order? fromStream = XmlUtil.Deserialize<Order>(stream, leaveOpen: true);

Null or empty input returns default. Stream deserialization starts at the current position and returns default when a seekable stream has no remaining bytes. XML declarations determine stream encoding automatically.

DTD processing is prohibited and external XML resolution is disabled. Malformed XML, schema/type mismatches, and serializer errors propagate. The utility does not impose a document-size limit, so constrain untrusted input before deserializing when resource exhaustion is a concern.

XmlSerializer instances are cached per closed generic type. Call the static methods directly; no dependency-injection registration is required.

Product Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Soenneker.Utils.Xml:

Package Downloads
Soenneker.Extensions.HttpResponseMessage

A collection of helpful HttpResponseMessage extension methods

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
11.0.1194 823 11/11/2026
11.0.1193 213 11/11/2026
11.0.1192 190 11/11/2026
11.0.1191 320 11/11/2026
11.0.1190 65 11/11/2026
11.0.1189 306 11/11/2026
11.0.1188 214 11/10/2026
11.0.1187 2,289 11/3/2026
11.0.1186 1,039 11/3/2026
11.0.1185 635 11/3/2026
11.0.1184 446 11/2/2026
11.0.1183 2,147 10/28/2026
11.0.1182 1,347 10/26/2026
11.0.1181 98 10/26/2026
11.0.1180 258 10/26/2026
11.0.1179 140 10/26/2026
11.0.1178 522 10/26/2026
4.0.1177 4,000 10/15/2026
4.0.1176 111 10/14/2026
4.0.1175 156 10/14/2026
Loading failed

Updated Multiple NuGet packages