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
<PackageReference Include="JJ.Framework.Xml.Legacy" Version="0.262.7664" />
<PackageVersion Include="JJ.Framework.Xml.Legacy" Version="0.262.7664" />
<PackageReference Include="JJ.Framework.Xml.Legacy" />
paket add JJ.Framework.Xml.Legacy --version 0.262.7664
#r "nuget: JJ.Framework.Xml.Legacy, 0.262.7664"
#:package JJ.Framework.Xml.Legacy@0.262.7664
#addin nuget:?package=JJ.Framework.Xml.Legacy&version=0.262.7664
#tool nuget:?package=JJ.Framework.Xml.Legacy&version=0.262.7664
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
- XmlToObjectConverter
- Elements
- Attributes
- Collections
- Composite Types
- Standard Naming
- Custom Naming
- Nullability
- Value Types
- Error Messages
- Performance
- 💬 Feedback
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
Tryvariations can return null. - The non-
Tryvariations 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 | Versions 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. |
-
.NETStandard 2.0
- JJ.Framework.Common.Legacy (>= 0.262.7664)
- JJ.Framework.PlatformCompatibility.Legacy (>= 0.262.7664)
- JJ.Framework.Reflection.Legacy (>= 0.262.7664)
-
.NETStandard 2.1
- JJ.Framework.Common.Legacy (>= 0.262.7664)
- JJ.Framework.PlatformCompatibility.Legacy (>= 0.262.7664)
- JJ.Framework.Reflection.Legacy (>= 0.262.7664)
-
net10.0
- JJ.Framework.Common.Legacy (>= 0.262.7664)
- JJ.Framework.PlatformCompatibility.Legacy (>= 0.262.7664)
- JJ.Framework.Reflection.Legacy (>= 0.262.7664)
-
net6.0
- JJ.Framework.Common.Legacy (>= 0.262.7664)
- JJ.Framework.PlatformCompatibility.Legacy (>= 0.262.7664)
- JJ.Framework.Reflection.Legacy (>= 0.262.7664)
-
net7.0
- JJ.Framework.Common.Legacy (>= 0.262.7664)
- JJ.Framework.PlatformCompatibility.Legacy (>= 0.262.7664)
- JJ.Framework.Reflection.Legacy (>= 0.262.7664)
-
net8.0
- JJ.Framework.Common.Legacy (>= 0.262.7664)
- JJ.Framework.PlatformCompatibility.Legacy (>= 0.262.7664)
- JJ.Framework.Reflection.Legacy (>= 0.262.7664)
-
net9.0
- JJ.Framework.Common.Legacy (>= 0.262.7664)
- JJ.Framework.PlatformCompatibility.Legacy (>= 0.262.7664)
- JJ.Framework.Reflection.Legacy (>= 0.262.7664)
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 |