einvoice-validator 0.1.0

Validate EN 16931 and Peppol BIS Billing 3.0 e-invoices against the official validation artefacts, in pure Rust
Documentation

einvoice-validator

Validate EN 16931 and Peppol BIS Billing 3.0 e-invoices against the official validation artefacts, in pure Rust: no JVM, no C library, no FFI.

A Validator is built once from a rule set (the XML schema it names loaded, its official compiled XSLT stylesheets prepared), is Send + Sync, and validates any number of documents. Each validation runs the XML check (UTF-8, well-formed, no document type declaration), the UBL 2.1 schema with einvoice-xsd, then every stylesheet of the rule set with einvoice-xslt-exec, which executes the official compiled Schematron with the behaviour of Saxon-HE 12.10. The Report holds the schema errors, the findings of each stylesheet (failed asserts and successful reports with their id, flag, location and message), the raw SVRL and the verdict.

[dependencies]
einvoice-validator = "0.1"
use einvoice_validator::{Validator, Verdict};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Built once: the UBL 2.1 schemas loaded, the CEN stylesheet prepared.
    let validator = Validator::cen_ubl()?;
    let invoice = br#"<Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"/>"#;
    let report = validator.validate(invoice)?;
    assert_eq!(report.verdict(), Verdict::Invalid);
    for finding in report.findings() {
        let id = finding.id.as_deref().unwrap_or("-");
        println!("{:?} {id}: {} (at {})", finding.severity, finding.text, finding.location);
    }
    Ok(())
}

Rule sets

  • Built in: cen-ubl, the CEN EN 16931 validation artefacts for UBL, release 1.3.17, embedded unmodified (default feature cen-ubl).
  • Bundles: a directory or in-memory set of files with a bundle.toml manifest naming the stylesheets and their SHA-256 (Validator::from_bundle_dir, Validator::from_bundle). Peppol BIS Billing 3.0 is used this way, since its files may not be redistributed: the repository's scripts/fetch-peppol.sh downloads the pinned release, compiles its stylesheets and writes the manifest.

On every case of the test corpora of CEN EN 16931 UBL 1.3.17 and Peppol BIS Billing 3.0.22, the verdicts and findings agree with Saxon-HE. The crate also builds for wasm32-unknown-unknown, where the caller gives the clock. The command-line tool is einvoice-cli (einvoice-validate).

This crate is part of einvoice-validator. Documentation: https://docs.rs/einvoice-validator.

Licence

MIT AND EUPL-1.2: the code is MIT, and the default feature cen-ubl embeds the CEN EN 16931 stylesheet, vendored unmodified in bundles/cen-ubl/, which is under the EUPL-1.2. Built with default-features = false, the crate embeds no rule set. Through einvoice-xsd, a program also embeds the OASIS UBL 2.1 schemas, which keep their own terms (OASIS, UN/CEFACT, W3C). The texts are in LICENSES/ of each crate, and einvoice_validator::licences() returns all of them, for programs that must show them to their users.