Skip to content

Validation

horstoeko edited this page Apr 12, 2024 · 22 revisions

Table of contents

Different mechanisms

There are generally two classes in this library that can validate documents:

  • A pure schema validation against the schema (XSD) by the class ZugferdXsdValidator.
  • A complete validation including business rules by the class ZugferdKositValidator. This class relies on an external tool from the Coordination Office for IT Standards (KoSIT) (German institution of the Federal Republic of Germany) to perform the validation. The validation currently only takes into account validation in accordance with EN16931 and the German CIUS XRechnung. For more details see KoSIT Validator on GitHub. At present, this feature is still to be considered experimental.

Pure XSD Validation

If only a pure validation against the XSD schema is required, then the class ZugferdXsdValidator is completely sufficient. A handling description is available in the form of an example implementation in the examples folder under XsdValidator.php.

Using the class ZugferdXsdValidator is very simple: When a new instance of this class is created, the constructor expects a parameter of the type ZugferdDocument. This makes it possible to check/validate both incoming documents from ZugferdDocumentReader and ZugferdDocumentPdfReader as well as outgoing documents from ZugferdDocumentBuilder:

From ZugferdDocumentReader:

$document = ZugferdDocumentReader::readAndGuessFromFile(dirname(__FILE__) . "/incoming.xml");

$xsdValidator = new ZugferdXsdValidator($document);
$xsdValidator->validate();

From ZugferdDocumentPdfReader:

$document = ZugferdDocumentPdfReader::readAndGuessFromFile(dirname(__FILE__) . "/incoming.pdf");

$xsdValidator = new ZugferdXsdValidator($document);
$xsdValidator->validate();

From ZugferdDocumentBuilder

$document = ZugferdDocumentBuilder::CreateNew(ZugferdProfiles::PROFILE_EN16931);
$document
    ->setDocumentInformation("471102", "380", \DateTime::createFromFormat("Ymd", "20180305"), "EUR")
    .....

$xsdValidator = new ZugferdXsdValidator($document);
$xsdValidator->validate();

After executing the validate method, further methods are available to determine any validation errors:

Method Description
$xsdValidator->validationPased Returns true or false. True if the validation has been passed successfully
$xsdValidator->validationFailed Returns true or false. True if the validation failed
$xsdValidator->validationErrors Returns an array of strings. Each array element contains a validation error

Validation using the Kosit Validation tool

For a more extensive validation, use the class ZugferdKositValidator. Attention! This class requires a functioning and complete JAVA installation (e.g. openjdk-11-jre-headless for Linux operating systems) to perform the validation correctly, as the external tool (KoSIT-Validator) is a pure JAVA application that is called by the class. A handling description is also available in the form of an example implementation in the examples folder under XsdValidator.php.

Please note: At present, this feature is still to be considered experimental.