JJ.Framework.Xml.Legacy 0.262.7664

Prefix Reserved
dotnet add package JJ.Framework.Xml.Legacy --version 0.262.7664
                    
NuGet\Install-Package JJ.Framework.Xml.Legacy -Version 0.262.7664
                    
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="JJ.Framework.Xml.Legacy" Version="0.262.7664" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="JJ.Framework.Xml.Legacy" Version="0.262.7664" />
                    
Directory.Packages.props
<PackageReference Include="JJ.Framework.Xml.Legacy" />
                    
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 JJ.Framework.Xml.Legacy --version 0.262.7664
                    
#r "nuget: JJ.Framework.Xml.Legacy, 0.262.7664"
                    
#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 JJ.Framework.Xml.Legacy@0.262.7664
                    
#: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=JJ.Framework.Xml.Legacy&version=0.262.7664
                    
Install as a Cake Addin
#tool nuget:?package=JJ.Framework.Xml.Legacy&version=0.262.7664
                    
Install as a Cake Tool

JJ.Framework.Xml.Legacy

Helpers for working with XML.

Legacy version updated to newest .NET versions, made trim-safe, compatible with AOT/native compilation. Fully documented and covered with tests.

Contents

XmlHelper

A class that gives access to XML. It does so in a null-safe and multiplicity-safe way. It uses XmlDocument as the underlying .NET API.

Members:

  • SelectNode / TrySelectNode
    • Select a node by XPath.
  • GetElement / TryGetElement / GetElements
    • Get child elements by name.
  • GetAttribute / TryGetAttribute
    • Get attributes by name.
  • GetAttributeValue / TryGetAttributeValue / SetAttributeValue
    • Get and set attribute values.

Remarks:

  • The Try variations can return null.
  • The non-Try variations cannot return null, but when nothing is found, will throw a clear exception instead.
  • The singular (non-plural) variations will throw a clear exception, when the item is not unique.

XmlToObjectConverter

Converts an XmlDocument or string to an object graph. The way to map to classes is easier than the classic ways in .NET. The idea was to make XML mapping intuitive and clean. (Also: At the time on certain platforms standard XML serialization was not available or not be the best option.)

Elements

By default properties are mapped to XML elements.

C#:

public int MyElement { get; set; }

XML:

<myElement>3</myElement>

Attributes

To map to XML attributes, mark a property with the XmlAttribute attribute.

C#:

[XmlAttribute]
public int MyAttribute { get; set; }

XML:

myAttribute="3"

Collections

If a property is a collection type, a parent XML element is expected, and a child element for each position in the array.

C#:

public int[] MyArray { get; set; }

XML:

<myArray>
  <int32>2</int32>
  <int32>3</int32>
  <int32>5</int32>
</myArray>

That single collection property maps to both this parent element and the child elements.

The supported collection types are Array types, List<T>, IList<T>, ICollection<T> and IEnumerable<T>.

Composite Types

You can easily work with composite types.

XML:

<myRoot>
  <myObject1 value="3" />
  <myObject2>
    <myArray>
      <item name="Name1" value="1" />
      <item name="Name2" value="2" >
        <childItem name="Child" value="3" />
      </item>
    </myArray>
  </myObject2>
</myRoot>

C#:

class MyRoot
{
    public MyClass MyObject1 { get; set; }
    public MyClass MyObject2 { get; set; }
}

class MyClass
{
    [XmlAttribute]
    public string Name { get; set; }

    [XmlAttribute]
    public int? Value { get; set; }

    [XmlArrayItem("item")]
    public MyClass[] MyArray { get; set; }

    public MyClass ChildItem { get; set; }
}

The composite types in the object structure must have parameterless constructors.

C#:

class MyClass
{
    // Having this constructor with a parameter causes an exception.
    public MyClass(int myConstructorParameter) { }
}

Standard Naming

By default the names in the XML are the camel-case version of the property names.

C#:

public int MyElement { get; set; }

XML:

<myElement>3</myElement>

Standard Naming for Collections

For XML array items, however, it is not the property name, but the camel case version of collection property's item type.

C#:

public int[] MyArray { get; set; }

XML:

<myArray>
  <int32>2</int32>
  <int32>3</int32>
  <int32>5</int32>
</myArray>

Custom Naming

To diverge from the standard naming , you can specify the node name explicitly by using the following .NET attributes on the properties: XmlElement, XmlAttribute, XmlArray and XmlArrayItem.

Custom Naming for Elements

C#:

[XmlElement("Elm")]
public int MyElement { get; set; }

XML:

<Elm>3</Elm>

Custom Naming for Attributes

C#:

[XmlAttribute("Attr")]
public int MyAttribute { get; set; }

XML:

Attr="3"

Custom Naming for Arrays

C#:

[XmlArray("Arr")]
[XmlArrayItem("Item")]
public int[] MyArray { get; set; }

XML:

<Arr>
  <Item>2</Item>
  <Item>3</Item>
  <Item>5</Item>
</Arr>

Nullability

Effort was made to make nullability as intuitive as possible.

Nullability for Reference Types

Reference types are always optional.

C#:

class MyRoot
{
	// Can be null
	public MyClass MyObject { get; set; }
}

XML:

<myRoot>
  
</myRoot>

Nullability for Value Types

Value types are optional, only if they are nullable.

C#:

class MyRoot
{
	// The '?' makes it OK to leave out the XML element.
	public int? MyElement { get; set; }
}

XML:

<myRoot>
  
  
</myRoot>

C#:

class MyRoot
{
	// Without the '?' the XML element is required.
	public int MyElement { get; set; }
}

XML:

<myRoot>
  
  <myElement>3</myElement>
</myRoot>

Nullability for Collections

Collection types are always optional.

C#:

class MyRoot
{
	public int[] MyArray { get; set; }
}

If the parent element is missing from the XML, the collection will be null.

XML:

<myRoot>
  
  
</myRoot>

If only the parent element is present, an empty collection will be assigned.

XML:

<myRoot>
  
  <myArray />
</myRoot>

Value Types

Recognized values are the .NET primitive types: Boolean, Char, Byte, IntPtr, UIntPtr, the numeric types, their signed and unsigned variations and String, Guid, DateTime, TimeSpan and Enum types.

Error Messages

Effort was put into making the exception messages clear and accurate if there are structure mismatches.

Performance

In short: performance is untested. I know it is a thing that people want to prove they have the fastest serializer. I really just wanted to map XML more easily. Other components I made depend on it.

Release Notes

2026-11-26 | 0.262/5.4 : Xml.Legacy Release
  • Releasing legacy XML to object mapper
  • Full code coverage
  • Docs completion
  • Code trimming / native AOT compilation support
  • Minor changes in nullability annotations and overloads

💬 Feedback

Found an issue? Let me know.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  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 is compatible.  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 is compatible.  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 is compatible.  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 is compatible.  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 is compatible. 
.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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
0.262.7664 69 11/26/2026