PHPackages                             doards/xrechnung-validator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. doards/xrechnung-validator

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

doards/xrechnung-validator
==========================

A PHP library to validate XRechnungen (UBL + EN16931) using SaxonC

v1.0.1(10mo ago)17MITXSLT

Since Jun 17Pushed 10mo agoCompare

[ Source](https://github.com/doards/xrechnung-validator-php)[ Packagist](https://packagist.org/packages/doards/xrechnung-validator)[ RSS](/packages/doards-xrechnung-validator/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (1)Versions (3)Used By (0)

XRechnung Validator for PHP
===========================

[](#xrechnung-validator-for-php)

This library validates **electronic invoices** (XRechnungen) according to:

- **UBL 2.1 structural rules** (via XSD validation)
- **EN 16931 semantic rules** (via Schematron using XSLT 2.0/3.0)

> 🛠️ Built for use with **SaxonC** (required for XSLT 3.0 in PHP)

📁 Installation
--------------

[](#-installation)

```
composer require doards/xrechnung-validator
```

---

🚀 Features
----------

[](#-features)

- ✅ UBL 2.1 XSD structure validation
- ✅ EN 16931 Schematron validation via XSLT
- ✅ Works with PHP 8.x
- ✅ Clean object-oriented API

---

📦 Requirements
--------------

[](#-requirements)

- PHP 8.1 or higher
- [SaxonC 12.x](https://www.saxonica.com/saxon-c/documentation12/index.html#!starting/installing) (must be installed and available via `saxon.so`)
- DOM extension (enabled by default in PHP)
- `DYLD_LIBRARY_PATH` (macOS) or `LD_LIBRARY_PATH` (Linux) must include the SaxonC library path

> ❗ `saxon.so` must be loaded via `php.ini` or a custom `.ini` file

---

Basic Usage
-----------

[](#basic-usage)

```
use Doards\XRechnungValidator\UBLStructureValidation;
use Doards\XRechnungValidator\EN16931Validator;

$xsdPath  = __DIR__ . '/resources/ubl/2.1/xsd/maindoc/UBL-Invoice-2.1.xsd';
$schematronXsltPath = __DIR__ . '/resources/peppol/billing-bis/3.0.18/PEPPOL-EN16931-UBL.xslt';
$xmlFile  = __DIR__ . '/examples/base-example.xml';

// Validate UBL structure
$ublValidator = new UBLStructureValidation($xsdPath);
$ublResult = $ublValidator->validate($xmlFile);

// Validate EN16931 semantic rules
$enValidator = new EN16931Validator($xsltPath);
$enResult = $enValidator->validate($xmlFile);

// Output results
print_r($ublResult);
print_r($enResult);
```

📄 HTML Report Output Both validators support an optional HTML reporting mode. When enabled, a results.html file will be created (or updated) in the project root.

✅ Example usage with HTML report enabled:

```
$ublValidator = new UBLStructureValidation($xsdPath);
$ublValidator->validate($xmlFile, true); // Will write UBL results to results.html

$enValidator = new EN16931Validator($xsltPath);
$enValidator->validate($xmlFile, true); // Will append EN results to the same file
```

The resulting results.html includes:

Clear sections per validation type

Errors (in red)

Warnings (in orange)

Extended Usage
--------------

[](#extended-usage)

### Running Validation from CLI to Avoid macOS / MAMP Fork() Issues

[](#running-validation-from-cli-to-avoid-macos--mamp-fork-issues)

Because SaxonC can cause stability problems in some environments (notably macOS with MAMP + Apache due to fork() issues), it is recommended to run the validation in a separate PHP CLI script instead of directly through the web server.

Example standalone CLI script (`xrechnung-valid.php`):

```
