Schematron 1.0.0
dotnet add package Schematron --version 1.0.0
NuGet\Install-Package Schematron -Version 1.0.0
<PackageReference Include="Schematron" Version="1.0.0" />
<PackageVersion Include="Schematron" Version="1.0.0" />
<PackageReference Include="Schematron" />
paket add Schematron --version 1.0.0
#r "nuget: Schematron, 1.0.0"
#:package Schematron@1.0.0
#addin nuget:?package=Schematron&version=1.0.0
#tool nuget:?package=Schematron&version=1.0.0
A .NET implementation of Schematron for validating XML with standalone .sch schemas or
Schematron rules embedded in W3C XML Schema. The library supports both the current ISO
Schematron namespace and the legacy ASCC namespace, with a compact public API centered on
Validator and Schema.
Installation
dotnet add package Schematron
The package targets netstandard2.0 and net8.0.
Usage
The package exposes two primary entry points:
Validatorloads Schematron and XML Schema definitions and validates XML documents.Schemaloads and inspects Schematron documents programmatically.
One-shot validation with a standalone Schematron schema
using Schematron;
var validator = new Validator();
validator.AddSchema("order.sch");
try
{
validator.Validate("order.xml");
Console.WriteLine("Document is valid.");
}
catch (ValidationException ex)
{
Console.WriteLine(ex.Message);
}
Validate returns the loaded IXPathNavigable document on success and throws
ValidationException when XML Schema or Schematron validation fails.
Validating XSD plus embedded Schematron
When the schema is a W3C XML Schema document with embedded Schematron, Validator runs
both validations in one pass:
using Schematron;
var validator = new Validator(OutputFormatting.XML);
// Use the overload with the target namespace when the XSD imports or includes other schemas.
validator.AddSchema("http://example.com/po-schematron", "po-schema.xsd");
try
{
validator.Validate("purchase-order.xml");
}
catch (ValidationException ex)
{
Console.WriteLine(ex.Message); // XML formatted output
}
Schematron-only validation for in-memory XML
If you already have an IXPathNavigable, use ValidateSchematron to skip XML Schema
validation and evaluate only the loaded Schematron rules:
using System.Xml.XPath;
using Schematron;
var validator = new Validator();
validator.AddSchema("rules.sch");
var document = new XPathDocument("order.xml");
validator.ValidateSchematron(document);
Selecting the phase, formatter, and return type
Validator lets you control the active phase, output format, and result type:
using Schematron;
using Schematron.Formatters;
var validator = new Validator(OutputFormatting.XML, NavigableType.XmlDocument)
{
Phase = "paymentInfo",
Formatter = new XmlFormatter(),
};
validator.AddSchema("purchase-order.sch");
var result = validator.Validate("purchase-order.xml");
Use Phase.All (#ALL) to evaluate every pattern regardless of phase activation.
Loading and inspecting a schema
Use Schema directly when you want to inspect a Schematron document without validating
an instance document yet:
using Schematron;
var schema = new Schema();
schema.Load("rules.sch");
Console.WriteLine(schema.Title);
Console.WriteLine(schema.SchematronEdition);
Console.WriteLine(schema.DefaultPhase);
Console.WriteLine(schema.IsLibrary);
Console.WriteLine(schema.Patterns.Count);
Console.WriteLine(schema.Lets.Contains("maxAge"));
This is useful for tooling, analyzers, test helpers, or apps that need to inspect declared
phases, patterns, diagnostics, parameters, and let bindings.
Core API
Schematron keeps the public surface intentionally small:
Validatoris the main entry point for loading schemas and validating XML.Schemaloads and inspects Schematron documents programmatically.OutputFormattingselects the built-in output style:Default/Log,Simple,Boolean, orXML.Validator.Phase,Validator.Formatter, andValidator.ReturnTypelet you choose the active phase, custom output formatter, and returned document type.BadSchemaExceptionsignals invalid schema input, whileValidationExceptionsignals XML or Schematron validation failures.
Supported features
The package currently supports the main scenarios expected for a v1 release, including:
- Standalone
.schschemas and Schematron embedded in W3C XML Schema - ISO Schematron namespace (
http://purl.oclc.org/dsdl/schematron) and legacy ASCC namespace compatibility - ISO Schematron 2025 features such as
<library>, phase@when, rule@visit-each, rule flags, and schema parameters - Schema-, pattern-, and rule-level
letbindings - Diagnostics, severity metadata, abstract patterns/rules, and groups
Open Source Maintenance Fee
To ensure the long-term sustainability of this project, users of this package who generate revenue must pay an Open Source Maintenance Fee. While the source code is freely available under the terms of the License, this package and other aspects of the project require adherence to the Maintenance Fee.
To pay the Maintenance Fee, become a Sponsor at the proper OSMF tier. A single fee covers all of Devlooped packages.
Sponsors
| 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 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 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
- No dependencies.
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.