XmlFluentValidator 1.0.0

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

πŸ”Ž Overview

XmlFluentValidator is a flexible XML validation library designed for scenarios where:

  • Validation rules must be defined programmatically
  • XML needs to be validated at runtime
  • XSD schemas must be generated from code-based rules
  • Some rules cannot be expressed in XSD but still need to be documented

The library combines a fluent builder API, runtime validation, and schema generation into a single, cohesive solution.

What you can do

  • Define XML validation rules using a fluent, readable API
  • Validate XML documents at runtime
  • Generate XSD schemas directly from validation rules
  • Document runtime-only rules (e.g., custom logic) using <xs:annotation>
  • Mix schema validation and custom validation seamlessly

✨ Key Features

Element Validation

  • Required / optional elements
  • Regex validation
  • Numeric and length ranges
  • Enumeration (enum-like constraints)
  • MaxOccurs and cardinality rules
  • Data type enforcement
  • Nullable (xs:nillable) support
  • Uniqueness constraints
  • Fixed(constant) value

Attribute Validation

  • Required attributes
  • Regex, range, length, and enumeration rules
  • Attribute uniqueness
  • Attribute-level documentation
  • Element–attribute cross-validation
  • Fixed(constant) value

Advanced Capabilities

  • Deeply nested paths (/customer/address/street)
  • Attribute shorthand (items/item@sku)
  • Cross-field validation
  • Global document rules
  • Custom, user-defined validation logic
  • Rule severity levels
  • Short-circuiting (StopOnFailure)
  • Automatic XSD documentation generation

πŸ“– Fluent Validator API Reference

  • .ForPath(xpath) β†’ For path. Rule for specific path.
  • .ForAttribute(xpath) β†’ For attribute. Rule for specific attribute.
  • .ForElement(elementPath) β†’ For element. Rule for specific element.
  • .UseSchema(schemaSet, [stopOnSchemaErrors]) β†’ .Use schema (for validation).
  • .GlobalRule(predicate, [message]) β†’ Global rule.
  • .Validate(doc) β†’ Validates the given document.

πŸ“– Fluent API Valdiation Rules Reference

Element Rules

  • .WithElementMustExist([message]) β†’ Must exist. The element must exist.
  • .WithElementCount(predicate, [message]) β†’ Counts.
  • .WithElementValue(predicate, [message]) β†’ Set validation rule for element value.
  • .WithElementOptional([message]) β†’ Specify the element validation as not required.
  • .WithElementRequired([message]) β†’ Set element validation rule as required.
  • .WithElementValueRequired([message]) β†’ Set element and value validation rule as required.
  • .WithElementMatchesRegex(pattern, [message]) β†’ Matches RegEx. Set element validation rule as regular expression.
  • .WithElementInRange(min, max, [isInclusive], [message]) β†’ In range. Set element validation rule as in range between minimum and maximum value.
  • .WithElementUnique([message]) β†’ Set element validation rule as unique value.
  • .WithElementMaxOccurs(max, [message]) β†’ Set element validation rule as maximum occurs.
  • .WithElementValueLength(min, [max], [message]) β†’ With element value length.
  • .WithElementDataType(dataType, [message]) β†’ With element data type.
  • .WithElementEnumerator(rangeEnumerator, [message]) β†’ With element enumerator (like enum values).
  • .WithElementExactLength(length, [message]) β†’ With element exact length.
  • .WithElementDocumentation(documentation) β†’ With element documentation. Set annotation/documentaion.
  • .WithElementNullable([isNullable], [message]) β†’ With element nullable.
  • .WithElementFixedValue(fixedValue, [message]) β†’ With element fixed(xonstant) value.

Attribute Rules

  • .WithAttribute(name, predicate, [message]) β†’ Set validation rule for element attribute.
  • .WithAttributeRequired(name, [message]) β†’ IsRequired attribute. Set attribute validation rule as required.
  • .WithAttributeValueRequired(name, [message]) β†’ IsRequired attribute. Set attribute and value validation rule as required.
  • .WithAttributeMatchesRegex(name, pattern, [message]) β†’ Attribute matches RegEx. Set attribute validation rule as regular expression.
  • .WithAttributeInRange(name, min, max, [isInclusive], [message]) β†’ Attribute in range. Set attribute validation rule as in range between minimum and maximum value.
  • .WithAttributeUnique(name, [message]) β†’ Attribute unique. Set specific attribute as unique.
  • .ElementAttributeCrossRule(name, predicate, [message]) β†’ Element attribute cross rule. Set cross validation for element and specific element attribute.
  • .WithAttributeValueLength(name, min, [max], [message]) β†’ With attribute value length.
  • .WithAttributeDataType(name, dataType, [message]) β†’ With attribute data type.
  • .WithAttributeEnumerator(name, rangeEnumerator, [message]) β†’ With attribute enumerator.
  • .WithAttributeExactLength(name, length, [message]) β†’ With attribute exact length.
  • .WithAttributeDocumentation(name, documentation) β†’ With attribute documentation.
  • .WithAttributeExactLength(name, fixedValue, [message]) β†’ With attribute fixed(xonstant) value.

Messages

  • .WithMessage(template, arguments) β†’ With message. Set custom validation message.
  • .WithMessage(message) β†’ With message. Set custom validation message.
  • .WithMessageForAll(message) β†’ With message for all.

Other rules

  • .All(predicate, [message]) β†’ All.
  • .Any(predicate, [message]) β†’ Any.
  • .When(condition, [message]) β†’ When the given condition.
  • .CustomElementRule(predicate, [message]) β†’ Custom element rule. an be used custom defined(registered) rule or defined in specific context.
  • .Custom(handler, [message]) β†’ Customs. Set the custom (user defined) validation method.
  • .UseCustomRule(ruleName, [message]) β†’ Use custom rule. Set the custom rule name for execution.
  • .WithName(displayName) β†’ With name. Set the specific name for path.
  • .WithSeverity(severity) β†’ With severity. Set the validation message severity.
  • .StopOnFailure() β†’ Stops on failure. Short-circuit within this rule chain.
  • .Done() β†’ Gets the done action. Ends the current element rule chain and returns to validator.

Custom Rules
.Custom(ctx =>
{
    var val = ctx.Document.XPathSelectElement("/order/id")?.Value;
    if (val == "0000")
        ctx.Failures.Add(new XmlValidationFailure
        {
            Severity = Severity.Error,
            Path = "/order/id",
            Message = "ID cannot be 0000"
        });
}, "ID must not be 0000")

Global Rules

.GlobalRule(doc =>
{
    return doc.XPathSelectElements("/order/items/item").Count() <= 10;
}, "Order must not contain more than 10 items")
Product 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 was computed.  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 was computed.  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
1.0.0 148 2/5/2026
1.0.0-rc.2 87 1/20/2026
1.0.0-rc.1 58 1/10/2026
1.0.0-alpha.4 57 1/5/2026
1.0.0-alpha.3 55 12/29/2025
1.0.0-alpha.2 228 12/18/2025
1.0.0-alpha 239 12/15/2025