ValidateInvoiceBusinessRulesWithPackage

Requires the Small Business edition — in Delphi, C++Builder and Lazarus code create the library as TPDFlibSmallBusiness (unit PDFlibSmallBusiness) or TPDFlibEnterprise; the Small Business and Enterprise DLL and ActiveX builds provide it unchanged; the Single edition keeps the method, which returns 0, an empty string or False and sets LastErrorCode to 901 (PDFLIB_ERROR_SMALLBUSINESS_REQUIRED)

E-invoicing

Description

Validates the embedded invoice XML against a rule package: a directory with a rulepackage.xml manifest that names the standard, version, schema and Schematron stylesheet and records the SHA-256 of every file

Syntax

Delphi

Function TPDFlib.ValidateInvoiceBusinessRulesWithPackage(Const EmbeddedFileName,
  PackageFile, PackageSHA256, XMLLintExecutable, JavaExecutable,
  SaxonClassPath: WideString; TimeoutMS: Integer): WideString; Virtual;

ActiveX

Function PDFlib::ValidateInvoiceBusinessRulesWithPackage(EmbeddedFileName As String, PackageFile As String, PackageSHA256 As String, XMLLintExecutable As String, JavaExecutable As String, SaxonClassPath As String, TimeoutMS As Long) As String

DLL

const wchar_t* DLValidateInvoiceBusinessRulesWithPackage(int InstanceID, const wchar_t* EmbeddedFileName, const wchar_t* PackageFile, const wchar_t* PackageSHA256, const wchar_t* XMLLintExecutable, const wchar_t* JavaExecutable, const wchar_t* SaxonClassPath, int TimeoutMS);
const char* DLValidateInvoiceBusinessRulesWithPackageA(int InstanceID, const char* EmbeddedFileName, const char* PackageFile, const char* PackageSHA256, const char* XMLLintExecutable, const char* JavaExecutable, const char* SaxonClassPath, int TimeoutMS);

Parameters

ParameterDescription
EmbeddedFileNameThe invoice attachment; empty selects the detected Factur-X or ZUGFeRD invoice
PackageFileThe rule package directory or its rulepackage.xml manifest
PackageSHA256The expected SHA-256 of the manifest as 64 hex digits, or empty. A pinned manifest guarantees that the package is the release you approved
XMLLintExecutableOptional xmllint for the schema stage; empty runs the built-in XML Schema validator
JavaExecutable, SaxonClassPathJava and SaxonJ for the package's Schematron stylesheet; with an empty JavaExecutable the business rules run through the built-in EN 16931 subset
TimeoutMSTimeout of each external tool; 0 selects 30000 ms

Return values

The validation report as JSON, as described for ValidateInvoiceBusinessRules, with a package object: manifest, sha256, pinned, verified, standard, version, profile, syntax, the schema and Schematron files, files with each path and digest, and error when verification failed

Remarks

A manifest looks like this; CreateInvoiceRulePackage writes it for a directory:

<?xml version="1.0" encoding="UTF-8"?>
<RulePackage xmlns="urn:pdflib:invoice-rule-package:1" standard="EN16931" version="1.3.16" profile="EN16931" syntax="CII">
  <Schema path="schema/FACTUR-X_EN16931.xsd"/>
  <Schematron path="schematron/EN16931-CII-validation.xslt"/>
  <File path="schema/FACTUR-X_EN16931.xsd" sha256="..."/>
  <File path="schema/FACTUR-X_EN16931_urn_un_unece_uncefact_data_standard_QualifiedDataType_100.xsd" sha256="..."/>
  <File path="schematron/EN16931-CII-validation.xslt" sha256="..."/>
</RulePackage>

Before validation every listed file is read and compared with its digest, paths must stay inside the package directory, and the standard and version come from the manifest. Each rule file is checked again right before an engine reads it, and the built-in schema validator accepts only imported schema documents that the manifest lists. Any failure stops both stages with an integrity issue instead of validating against unverified rules

The built-in XML Schema validator supports the schema features invoice schemas use: global and local elements and references, named and anonymous types, sequence, choice and all groups with occurrence bounds, wildcards, simple and complex content by extension or restriction, attributes, enumerations, ID uniqueness and the lexical forms of the built-in types such as decimal, date and dateTime. A schema with other constructs, such as substitution groups or model group references, fails to load with XSD.Unsupported; pattern and length facets and identity constraints are listed in notCovered

fullConformance is true only when the package is verified, both stages pass and both ran the package's rules completely, so it needs JavaExecutable for packages with a Schematron stylesheet

Example

Report:= PDF.ValidateInvoiceBusinessRulesWithPackage('', 'C:\Rules\EN16931-CII-1.3.16',
  '9f2c...e41a', '', 'C:\Java\bin\java.exe', 'C:\Saxon\saxon-he.jar', 0);

See also

CreateInvoiceRulePackage, GetInvoiceRulePackageInfo, ValidateInvoiceBusinessRules, ValidateInvoiceBusinessRulesWithTools