BeneficialStrategies.Iso20022.Validation.Xml
1.0.0
dotnet add package BeneficialStrategies.Iso20022.Validation.Xml --version 1.0.0
NuGet\Install-Package BeneficialStrategies.Iso20022.Validation.Xml -Version 1.0.0
<PackageReference Include="BeneficialStrategies.Iso20022.Validation.Xml" Version="1.0.0" />
<PackageVersion Include="BeneficialStrategies.Iso20022.Validation.Xml" Version="1.0.0" />
<PackageReference Include="BeneficialStrategies.Iso20022.Validation.Xml" />
paket add BeneficialStrategies.Iso20022.Validation.Xml --version 1.0.0
#r "nuget: BeneficialStrategies.Iso20022.Validation.Xml, 1.0.0"
#:package BeneficialStrategies.Iso20022.Validation.Xml@1.0.0
#addin nuget:?package=BeneficialStrategies.Iso20022.Validation.Xml&version=1.0.0
#tool nuget:?package=BeneficialStrategies.Iso20022.Validation.Xml&version=1.0.0

BeneficialStrategies.Iso20022.Validation.Xml
Validate ISO 20022 XML straight from text, a document or an element: every problem is reported with its path, then the FluentValidation rules run on what was read.
Read ISO 20022 XML into an object and validate it in one call. You get your object, populated, or every problem found, in the same ValidationResult FluentValidation always gives you, each with the path of the XML element it is about.
The package is built so that you take only what you need. It needs BeneficialStrategies.Iso20022.Primitives (the ISO primitive types, the code sets and the XML reader) and FluentValidation, nothing else: not the message definitions, not the records. Three examples follow, each adding one thing.
How to use
Your own class
You do not need the ISO 20022 message library to use this. You need a class of your own whose members are ISO 20022 primitive types, and the XML to read into it.
public class MyParty
{
[IsoXmlTag("Name")]
public required Max35Text Name { get; init; } // a primitive type: at most 35 characters
[IsoXmlTag("ChargeBearer")]
public required ChargeBearerType1Code ChargeBearer { get; init; } // a code set: DEBT, CRED, SHAR or SLEV
}
// An ordinary FluentValidation validator. Put rules of your own in it; the ISO rules of the types are enforced as the XML is read.
public class MyPartyValidator : AbstractValidator<MyParty> { }
Read some XML into it:
var xml = XElement.Parse("<Party><Name>Acme Corp</Name><ChargeBearer>SHAR</ChargeBearer></Party>");
ValidationResult result = validator.Validate(xml, out MyParty? mine);
if (result.IsValid)
Console.WriteLine($"{mine!.Name} pays {mine.ChargeBearer}"); // Acme Corp pays Shared
else
foreach (var failure in result.Errors)
Console.WriteLine($"{failure.ErrorCode} {failure.PropertyName}: {failure.ErrorMessage}");
With bad XML, mine is null and the result lists every problem, not only the first:
var tooLong = XElement.Parse("<Party><Name>A name that is a good deal longer than thirty-five characters</Name><ChargeBearer>FREE</ChargeBearer></Party>");
var problems = validator.Validate(tooLong, out MyParty? none);
foreach (var failure in problems.Errors)
Console.WriteLine($"{failure.ErrorCode} {failure.PropertyName}: {failure.ErrorMessage}");
Console.WriteLine(none is null); // True: nothing is built from XML that cannot be read
Xml.FacetViolation Party/Name: 'Max35Text' allows at most 35 character(s) but received 61: 'A name that is a good deal longer than thirty-f...'.
Xml.BadValue Party/ChargeBearer: 'FREE' is not a value of ChargeBearerType1Code. Expected one of: DEBT, CRED, SHAR, SLEV.
True
A missing element is a problem too:
var missing = XElement.Parse("<Party><Name>Acme Corp</Name></Party>");
var absent = validator.Validate(missing, out MyParty? alsoNone);
foreach (var failure in absent.Errors)
Console.WriteLine($"{failure.ErrorCode} {failure.PropertyName}: {failure.ErrorMessage}");
Xml.RequiredMissing Party/ChargeBearer: Required element <ChargeBearer> is missing.
What made that work: [IsoXmlTag] says which element a member is read from; required makes a missing element an error; and the types Max35Text and ChargeBearerType1Code carry their ISO format rules with them, so they are checked while reading. Declare the out variable with its type (out MyParty? mine; out var mine does not compile): that is how the reader knows what to build.
Try the project yourself.
With the message records
You would rather not write the classes: ISO 20022 has thousands of them. BeneficialStrategies.Iso20022.Messages.Records has every message, component and choice as a ready-made class. Read an element of a message into its record, or a whole document into the record of the message:
var header = XElement.Parse(
"<GrpHdr><MsgId>MSG-001</MsgId><CreDtTm>2026-01-01T00:00:00</CreDtTm><NbOfSttlmReqs>1</NbOfSttlmReqs></GrpHdr>");
var result = validator.Validate(header, out GroupHeader104? read); // the record, named by the out variable
Console.WriteLine($"{result.IsValid} {read!.MessageIdentification.Value}"); // True MSG-001
Your rules are written for the interface of the type (IGroupHeader104), not for a class, so they work on whatever implements it:
// A rule of your own, written for the interface, so it works on a record, on an object of the Factory or on a class of yours.
public class MyGroupHeaderRules : AbstractValidator<IGroupHeader104>
{
public MyGroupHeaderRules() =>
RuleFor(x => x.NumberOfSettlementRequests.Value).Equal("1").WithMessage("This integration sends one request per message.");
}
An element that cannot be read is reported, with its path, before any rule runs:
var bad = XElement.Parse(
"<GrpHdr><MsgId>A message identification of well over thirty-five characters</MsgId><CreDtTm>2026-01-01T00:00:00</CreDtTm><NbOfSttlmReqs>1</NbOfSttlmReqs></GrpHdr>");
var problems = validator.Validate(bad, out GroupHeader104? unread);
foreach (var failure in problems.Errors)
Console.WriteLine($"{failure.ErrorCode} {failure.PropertyName}");
Try the project yourself.
Without the classes: the Factory
You want the message's shape, not 3,339 implementations of it. Give the reader a Factory and read into the interface; the object is made for you:
public interface IMyParty
{
[IsoXmlTag("Name")] Max35Text Name { get; }
[IsoXmlTag("ChargeBearer")] ChargeBearerType1Code ChargeBearer { get; }
}
public class MyPartyRules : AbstractValidator<IMyParty> { }
var xml = XElement.Parse("<Party><Name>Acme Corp</Name><ChargeBearer>SHAR</ChargeBearer></Party>");
var result = validator.Validate(xml, factory, out IMyParty? party); // an object of a class built for the interface
Console.WriteLine($"{result.IsValid} {party!.Name} pays {party.ChargeBearer}"); // True Acme Corp pays Shared
Try the project yourself.
More
- Documentation, release notes and issues: https://github.com/Beneficial-Strategies/iso-20022-validation-xml
- License: MIT. Status: stable.
Every call has an async form and takes a document, an element or text
Validate and ValidateAsync read from a string, an XDocument or an XElement. An element from inside a larger document is read with a ReadContext (its namespace and the path prefix to put in front of the problems).
The rules of ISO's own messages
The validators for ISO's own messages, written for the interfaces, are a separate package: BeneficialStrategies.Iso20022.Messages.Validation. They are IValidator<T>, so they work with the calls above. This package does not depend on them.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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 was computed. 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 was computed. 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 was computed. |
| .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
- BeneficialStrategies.Iso20022.Primitives (>= 1.1.1 && < 1.2.0)
- FluentValidation (>= 11.12.0)
-
net10.0
- BeneficialStrategies.Iso20022.Primitives (>= 1.1.1 && < 1.2.0)
- FluentValidation (>= 11.12.0)
-
net8.0
- BeneficialStrategies.Iso20022.Primitives (>= 1.1.1 && < 1.2.0)
- FluentValidation (>= 11.12.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on BeneficialStrategies.Iso20022.Validation.Xml:
| Package | Downloads |
|---|---|
|
BeneficialStrategies.Iso20022.Validation.Xml.Payloads
Validate raw ISO 20022 XML or JSON payloads as they arrive from a queue, an HTTP body or a file: the payload is read, then validated with the FluentValidation validators registered for the message; a payload that cannot be read comes back as ordinary FluentValidation failures. Needs only the Primitives and Validation.Xml packages, not the message definitions. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 152 | 10/26/2026 |
| 1.0.0-alpha | 147 | 10/23/2026 |
Added: First stable release: read ISO 20022 XML into an object and validate it in one call, depending on the stable Primitives 1.1.1 (#11).
Changed: Run the netstandard2.0 build on .NET Framework 4.8 in CI (test gap) (#2).