Raitung.Schematron
1.0.0-alpha.1
dotnet add package Raitung.Schematron --version 1.0.0-alpha.1
NuGet\Install-Package Raitung.Schematron -Version 1.0.0-alpha.1
<PackageReference Include="Raitung.Schematron" Version="1.0.0-alpha.1" />
<PackageVersion Include="Raitung.Schematron" Version="1.0.0-alpha.1" />
<PackageReference Include="Raitung.Schematron" />
paket add Raitung.Schematron --version 1.0.0-alpha.1
#r "nuget: Raitung.Schematron, 1.0.0-alpha.1"
#:package Raitung.Schematron@1.0.0-alpha.1
#addin nuget:?package=Raitung.Schematron&version=1.0.0-alpha.1&prerelease
#tool nuget:?package=Raitung.Schematron&version=1.0.0-alpha.1&prerelease
Raitung
Raitung is a C# library that creates, reads and validates German and European e-invoices (EN 16931 in the ZUGFeRD / Factur-X hybrid PDF form and as XRechnung XML) on .NET 10, without native or Java dependencies at run time.
The name
Raitung is an old German word for rendering accounts: the statement of income and expenses that anyone who managed someone else's money had to present at regular intervals (Deutsches Rechtswörterbuch: Reitung). It comes from the verb raiten, "to calculate, to render an account, to pay"; in miners' language it meant rendering the account of a mine's housekeeping (Grimm, Deutsches Wörterbuch: rait). The word survives in Austrian administrative history (Wien Geschichte Wiki: Rait…).
Where raiten comes from is disputed. Grimm relates it to Old High German reiti, "ready": to count is to set out, to make ready, perhaps first the price of a purchase. The Wien Geschichte Wiki derives it from the Latin ratiocinor, "to calculate".
An invoice is a small Raitung: an account of what is owed, which this library writes, reads and checks.
Status
The five NuGet packages target .NET 10 and share prerelease version 1.0.0-alpha.1.
Install Raitung for the CII model, Raitung.Ubl for UBL, Raitung.Pdf for
hybrid PDFs, or Raitung.Validation for invoice validation. Raitung.Schematron
can also be used independently.
The core package includes:
- the EN 16931 semantic model as immutable records (parties, payment instructions, allowances and charges, lines, VAT breakdown, totals), for invoices (380) and credit notes (381);
- totals calculation with EN 16931 rounding, and a check of stored totals against BR-CO-10 to BR-CO-17;
- a CII (UN/CEFACT D22B, Factur-X 1.09.2) writer and reader;
- XSD validation against the bundled schema of the profile (the FeRD schemas of the Factur-X profiles, UN/CEFACT D16B for XRechnung), with line and position for each error;
- profiles (BT-24) and code lists as data;
- XRechnung 3.0 support:
XRechnungInvoice.Preparesets the XRechnung specification identifier and business process,XRechnungInvoice.Checkreports the data the BR-DE rules demand (with their rule IDs and severities) before anything is written, andLeitwegIdchecks and builds Leitweg-IDs (form and MOD 97-10 check digits, KoSIT format specification 2.0.2).
The package is trimming- and Native AOT-compatible and has no dependencies.
src/Raitung.Ubl writes and reads OASIS UBL 2.1 Invoice and CreditNote documents with the
CEN EN 16931 UBL binding: credit note type codes (381 and the others of BR-CL-01) become a
CreditNote, every other type an Invoice. The writer is deterministic and never writes an empty
element; the reader is tolerant (extensions and unknown elements are skipped). The few terms UBL
cannot hold as the model does are listed in docs/decisions.md (M4). It is
Native AOT-compatible and depends on the core package only.
src/Raitung.Pdf (a prerelease while its PdfPig dependency is a nightly) turns an existing PDF
into a PDF/A-3b hybrid invoice (Factur-X / ZUGFeRD 2.x / XRechnung in CII) and extracts the XML
again:
- the invoice XML is added by an appended incremental update, so the original PDF's bytes stay unchanged; the update adds XMP metadata (merged into existing XMP), an sRGB output intent when the PDF has none, and the XML as an embedded, associated file;
- the output is deterministic: with a fixed timestamp, the same input gives the same bytes;
- a pre-flight check rejects, with typed errors, PDFs that an update cannot make PDF/A-3b (for example encrypted PDFs, fonts that are not embedded, CMYK content without a CMYK output intent, JavaScript) and PDFs that already carry an invoice;
- extraction finds
factur-x.xml,zugferd-invoice.xml,ZUGFeRD-invoice.xmlandxrechnung.xml, in any case, in the embedded files or the associated files.
It is Native AOT-compatible and depends on the core package and PdfPig.
src/Raitung.Schematron is an ISO Schematron engine with an XPath 2.0 subset and
xsl:function, written in C# without dependencies. Rules are compiled once and can be used from
any number of threads. Where Saxon (which the KoSIT validator and Mustang run) departs from the
XPath specification, the engine follows Saxon and reports a notice whenever that changes a result.
Its findings match Saxon's on every document of the test corpora (see "Oracle" below).
document() reads only files supplied with the rules; a construct the engine does not implement
is an error when the rules are loaded, never a silent pass.
src/Raitung.Validation (a prerelease because it depends on the PDF package) validates
e-invoices in CII and UBL, also from a hybrid PDF:
- the format first: well-formedness and the XSD of the scenario; a format error ends the validation;
- then the Schematron rule sets of the scenario that the specification identifier (BT-24) selects: the FeRD rules for the Factur-X / ZUGFeRD profiles MINIMUM to EXTENDED, and the scenarios of the KoSIT configuration for XRechnung 3.0.2 (CEN EN 16931 1.3.16 plus XRechnung 2.6.0 rules, with the KoSIT severity overrides);
- a report with a status (valid, invalid, or not checkable with the reason), format findings apart from business-rule findings, and per finding the rule ID, severity (from the rule's flag, as the KoSIT validator derives it), outcome, location, line and message.
With ValidationScenarios.KoSit it gives the KoSIT validator's verdict on every document of the
test corpora. The CEN EN 16931 rules are licensed under EUPL-1.2 and are not bundled; see
CEN rules.
Not done yet: the Peppol BIS rules, and writing the terms of the XRechnung extension (documents that
use it are read, without those terms). The feasibility spikes for M2 and M3 are under spike/; they
are throwaway code. Design decisions are in
docs/decisions.md.
Usage
using Raitung;
using Raitung.Calculation;
using Raitung.Cii;
using Raitung.CodeLists;
var invoice = InvoiceCalculator.Calculate(new Invoice
{
Number = "RE-2026-1000",
IssueDate = new DateOnly(2026, 12, 3),
CurrencyCode = "EUR",
PaymentDueDate = new DateOnly(2027, 1, 2),
Seller = new Party
{
Name = "Muster Software GmbH",
VatIdentifier = "DE123456789",
Address = new PostalAddress { City = "Berlin", CountryCode = "DE" },
},
Buyer = new Party
{
Name = "Beispiel AG",
Address = new PostalAddress { City = "München", CountryCode = "DE" },
},
Lines =
[
new InvoiceLine
{
Id = "1",
Quantity = 12m,
UnitCode = UnitCodes.Hour,
Price = new PriceDetails { NetPrice = 95.00m },
VatCategoryCode = VatCategoryCodes.StandardRate,
VatRate = 19m,
Item = new Item { Name = "Consulting" },
},
],
});
byte[] xml = CiiWriter.ToBytes(invoice); // deterministic UTF-8 CII
ValidationReport report = CiiSchemaValidator.Validate(xml); // XSD; the profile comes from BT-24
Invoice read = CiiReader.Read(xml); // read == invoice
InvoiceCalculator.Calculate fills in line net amounts, the VAT breakdown and the document totals.
For a Factur-X MINIMUM invoice, supply its header data and stored totals directly; Calculate
returns such an invoice unchanged. The profile excludes lines, their net total (BT-106) and the
allowance and charge totals (BT-107, BT-108). The reader returns null for the net total and the
writer omits all three. Setting BT-24 alone does not convert a detailed invoice to the MINIMUM profile.
CiiWriter writes the model as it is and does not recalculate. TotalsVerifier.Verify reports
totals that do not match the lines, with the rule ID (BR-CO-10 to BR-CO-17).
Hybrid PDF
using Raitung.Pdf;
byte[] carrier = File.ReadAllBytes("invoice.pdf"); // the PDF that shows the invoice
byte[] hybrid = HybridPdf.Create(carrier, invoice); // PDF/A-3b with factur-x.xml embedded
EmbeddedInvoice? embedded = HybridPdf.Extract(hybrid); // null when there is no invoice XML
Invoice fromPdf = embedded!.ReadInvoice(); // fromPdf == invoice
HybridPdf.Create also takes the XML as bytes or streams. HybridPdfOptions sets the profile
(otherwise taken from BT-24 in the XML), the attachment's file name and /AFRelationship (per
profile by default: factur-x.xml or xrechnung.xml; Alternative, or Data for MINIMUM and
BASIC WL) and the timestamp. A carrier the pre-flight check rejects raises a HybridPdfException
whose Problems say why; HybridPdf.Check returns them without creating anything. The check is
not a PDF/A validator: run veraPDF on your own carriers once, as the conformance gate below does
for the test carriers.
UBL and XRechnung
using Raitung.Ubl;
using Raitung.XRechnung;
var xrechnung = XRechnungInvoice.Prepare(invoice with // BT-24 and BT-23 of XRechnung 3.0
{
BuyerReference = LeitwegId.Create("04011000", "12345"), // the Leitweg-ID 04011000-12345-03
Seller = invoice.Seller with
{
ElectronicAddress = new Identifier("rechnung@muster.example", "EM"),
Address = new PostalAddress { City = "Berlin", PostCode = "10115", CountryCode = "DE" },
Contact = new Contact { Name = "Erika Mustermann", Telephone = "+49 30 1234567", Email = "erika@muster.example" },
},
Buyer = invoice.Buyer with
{
ElectronicAddress = new Identifier("einkauf@beispiel.example", "EM"),
Address = new PostalAddress { City = "München", PostCode = "80331", CountryCode = "DE" },
},
Delivery = new Delivery { ActualDeliveryDate = new DateOnly(2026, 11, 30) },
PaymentInstructions = new PaymentInstructions
{
TypeCode = PaymentMeansCodes.SepaCreditTransfer,
CreditTransfers = [new CreditTransfer { Iban = "DE02120300000000202051" }],
},
});
ValueList<ValidationIssue> missing = XRechnungInvoice.Check(xrechnung); // BR-DE data; empty here
byte[] ubl = UblWriter.ToBytes(xrechnung); // UBL 2.1 Invoice
Invoice fromUbl = UblReader.Read(ubl); // fromUbl == xrechnung
byte[] cii = CiiWriter.ToBytes(xrechnung); // the same XRechnung in CII
XRechnungInvoice.Check is a check of the data, not a validation: it reports what XRechnung
requires beyond EN 16931 (buyer reference, seller contact, payment means that match the payment
data, cash discount lines, and so on), and warns when a buyer reference looks like a Leitweg-ID
but has wrong check digits. The verdict comes from the validator below, which needs the CEN rules
for XRechnung. LeitwegId.IsValid and LeitwegId.Check test a Leitweg-ID on its own.
An XRechnung in CII can also be embedded in a PDF: HybridPdf.Create takes the profile from BT-24
and names the attachment xrechnung.xml.
Validation
using Raitung.Validation;
var validator = new InvoiceValidator(); // the rules for Factur-X are embedded
InvoiceValidationReport result = validator.Validate(xml); // or ValidatePdf(hybrid)
foreach (ValidationFinding finding in result.Findings)
{
Console.WriteLine(finding); // kind, severity, rule ID, message
}
result.Status is Valid, Invalid or NotCheckable. A document is invalid when it is not
well-formed, violates the schema (FormatFindings), or breaks a rule whose effective severity is
an error; warnings and information do not make it invalid. It is not checkable when no scenario
matches its specification identifier, when a rule could not be evaluated (a dynamic error, listed
as a finding with outcome Error), or when a rule set the scenario needs was not supplied.
result.RuleSets tells which rule sets ran, and result.Notices lists, among others, every place
where the Saxon-compatible evaluation changed a result (InvoiceValidatorOptions.SaxonCompatible
turns it off).
By default the identifier urn:cen.eu:en16931:2017 in CII selects the Factur-X EN 16931 profile
with the FeRD rules, as Mustang checks it. To check exactly as the KoSIT validator does (D16B schema
and the CEN rules for that identifier too), pass Scenarios = ValidationScenarios.KoSit.
CEN rules
The XRechnung and EN 16931 scenarios need the CEN EN 16931 validation rules, which are licensed
under EUPL-1.2 and therefore not part of the packages. Download release 1.3.16 from
ConnectingEurope/eInvoicing-EN16931
(en16931-cii-1.3.16.zip, SHA-256 1cd53cb8a84d38aedc82c0caede217da983a7934dd663f793a092fd66443c561;
en16931-ubl-1.3.16.zip, SHA-256 bafada015efbc5248bf5e05ad2191e1d9833ef96e9dd5f4bce420a747342da85)
and pass them in:
CenRules cen = CenRules.FromArchives(File.OpenRead("en16931-cii-1.3.16.zip"), File.OpenRead("en16931-ubl-1.3.16.zip"));
// or CenRules.FromDirectory("rules/cen-1.3.16") with cii/ and ubl/ unpacked below it,
// or CenRules.FromSchematron(ciiStream, ublStream) with the preprocessed .sch files
var xrechnung = new InvoiceValidator(new InvoiceValidatorOptions { CenRules = cen });
eng/fetch-cen-rules.sh (just fetch-cen-rules) downloads and verifies both archives and unpacks
them for FromDirectory. Other releases are accepted; the report then notes that they are not the
tested release. Without the CEN rules, an XRechnung document is never reported valid: it is invalid
when the XRechnung rules find an error, and otherwise not checkable (RulesNotSupplied).
A complete example that publishes with Native AOT is in samples/Raitung.Samples.Aot.
Requirements
- .NET SDK 10
- Docker, for the external validators (Mustang, veraPDF, KoSIT). They are test tools only.
- just, optional, to run the recipes in
justfile
Build and test
just build
just test
To publish the sample with Native AOT and run it (it also writes and validates an XRechnung in UBL,
with the CEN rules if just fetch-cen-rules has put them into .tools/):
just publish-sample
To check the generated sample invoices with the Mustang validator in Docker:
just mustang
To run the conformance gate for hybrid PDFs: every hybrid invoice made from the generated test carriers (Factur-X and XRechnung in CII, and the AOT sample's, if published) must pass veraPDF (PDF/A-3b) and Mustang, and every negative probe must fail. It runs both validators in Docker and downloads the Mustang jar on the first run.
just conformance
Oracle
The Schematron engine and the validation package are tested against the reference
implementations: Saxon-HE 12.8 in the KoSIT validator 1.6.3 (the CEN, FeRD and XRechnung rules)
and the KoSIT validator's own verdicts. Their results are checked in as expectations under
tests/oracle/expected/, so the tests need neither Docker nor Java. Some inputs are not checked
in: the CEN rules and examples (EUPL-1.2) and the XRechnung test suite. Without them the tests that
need them are skipped with a message saying what to fetch:
just fetch-test-inputs # CEN rules 1.3.16, XRechnung test suite, fetched corpora (into .tools/)
just test
That runs everything except two groups. The comparison with the KoSIT scenarios.xml needs the
KoSIT configuration (just fetch-oracles). The expectations for the CEN example invoices name
EUPL-1.2 files, so they are not checked in either: generate them locally (into
.tools/oracle/expected/) with the oracles in Docker. The same recipes regenerate all expectations
after a corpus or a rule version changes:
just fetch-oracles
just oracle-refresh # or: just oracle-refresh cii-cen-examples ubl-cen-examples
The library's own output is one of the corpora: the sample invoices written as CII and as UBL,
EN 16931 and XRechnung (tests/oracle/corpora/*-generated), all of which the KoSIT validator
accepts. A test fails when the writers' output drifts from them; after a deliberate change to a
writer, rewrite them and refresh their expectations:
just update-generated-corpora
just oracle-refresh cii-generated ubl-generated
Limitations
Raitung follows the published specifications and is tested against the KoSIT validator and Mustang, but its validation result is not a legal or tax assessment of an invoice. The official KoSIT validator remains the reference for XRechnung. The bundled rules are those of the releases named above; when KoSIT, FeRD or CEN publish new releases, the packages must be updated to follow them.
Contributing and security
See CONTRIBUTING.md for how to build, test and submit changes. Report vulnerabilities privately as described in SECURITY.md.
License
Apache-2.0. See LICENSE and NOTICE. The bundled Factur-X XSDs, the FeRD and XRechnung Schematron rules and the code list data are Apache-2.0; the UN/CEFACT and OASIS UBL schemas are redistributed under their owners' notices; the bundled sRGB ICC profile is CC0; see THIRD-PARTY-NOTICES. The CEN EN 16931 rules (EUPL-1.2) are not included.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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. |
-
net10.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Raitung.Schematron:
| Package | Downloads |
|---|---|
|
Raitung.Validation
Validation of EN 16931 e-invoices for .NET: XSD plus the official Schematron rules (Factur-X / ZUGFeRD profiles by FeRD, XRechnung by KoSIT, and the CEN EN 16931 rules supplied at run time) for CII and UBL, also from hybrid PDFs, with a classified report whose verdicts match the KoSIT validator. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0-alpha.1 | 0 | 12/4/2026 |