Skip to content

Add optional XSD validation - #256

Merged
BorislavSabev merged 1 commit into
php-sepa-xml:masterfrom
BorislavSabev:feature/xsd-validation
Sep 14, 2026
Merged

BorislavSabev merged 1 commit into
php-sepa-xml:masterfrom
BorislavSabev:feature/xsd-validation

Conversation

@BorislavSabev

Copy link
Copy Markdown
Member

Changelog

Added

  • BaseDomBuilder::validateSchema(?string $xsdFile = null): bool — validates the generated XML against an XSD. Defaults to the ISO 20022 XSD bundled for the builder's pain format; pass a path to validate against a bank's variant XSD.
  • BaseDomBuilder::getSchemaValidationErrors(?string $xsdFile = null): array — same, but returns one Line N: message string per error; empty when the document is valid.
  • Passthroughs for both on BaseCustomerTransferFileFacade. They render the document first, with the same single-shot semantics as asXML().
  • MessageFormat::getBundledSchemaPath(): ?string — path to the bundled XSD for a format, or null when none is bundled.
  • tests/Unit/DomBuilder/SchemaValidationTest.php — 52 tests: every supported format has a bundled XSD matching the test fixture, valid SCT/SDD files pass for every pain.001.001.x / pain.008.001.x version, errors are reported, explicit paths are used, exceptions for missing XSDs, libxml state is restored, and the facade passthroughs.

Changed

  • ext-libxml moved from require-dev to require; BaseDomBuilder now calls libxml_* functions.
  • Docs: doc/guides/output-and-validation.md no longer claims the XSDs aren't shipped and documents the new methods; DomBuilder, facade and exceptions reference pages updated.

Notes

  • No new files in the package: the XSDs are the ones already under doc/ISO20022/. A test fails if .gitattributes ever excludes that directory.
  • Validation runs on a re-parsed copy of the XML. Validating asDoc() directly always fails, because the root's xmlns is set as an attribute and the in-memory elements aren't in the schema's namespace.
  • Files built with setOmitAgentElementIfBicMissing(true) can fail the base ISO XSD (it drops mandatory DbtrAgt/CdtrAgt). Validate those against the bank's own XSD.
  • InvalidArgumentException is thrown when the XSD path doesn't exist, or when no XSD is bundled for the format and none was passed.
  • The methods aren't added to DomBuilderInterface or CustomerTransferFileFacadeInterface, so custom implementations don't break.

@BorislavSabev
BorislavSabev merged commit 1b87601 into php-sepa-xml:master Sep 14, 2026
2 checks passed
@BorislavSabev
BorislavSabev deleted the feature/xsd-validation branch September 14, 2026 13:01
@BorislavSabev BorislavSabev mentioned this pull request Sep 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant