Skip to content

Add XML structure validation for PEPPOL rules #34

Description

@fank

Summary

Implement XML structure validation for PEPPOL BIS Billing 3.0, particularly empty element checks.

Background

Some PEPPOL rules require validating the XML structure itself, not just the parsed Invoice struct. The most notable example is PEPPOL-EN16931-R008: "Document MUST not contain empty elements" (including whitespace-only content).

Current implementation in PR #32 only validates business logic on the Invoice struct, which happens after XML parsing. Structure-level validation requires checking the raw XML.

Requirements

PEPPOL-EN16931-R008

Documents must not contain empty XML elements, including:

  • Completely empty: <Element/>
  • Whitespace-only: <Element> </Element>
  • Newline-only: <Element>\n</Element>

This rule ensures clean, well-formed invoices without unnecessary empty tags.

Other Potential Structure Rules

May need to validate:

  • Element ordering
  • Namespace usage
  • Attribute presence/format
  • Comment restrictions

Implementation Options

Option 1: Parse-time validation

Add validation during XML parsing in parser.go:

  • Use encoding/xml Decoder events
  • Check for empty elements before populating Invoice struct
  • Report violations immediately

Option 2: Post-parse XML validation

After successful parsing:

  • Re-read the XML file
  • Use XPath or DOM traversal
  • Check structure rules
  • Combine with business rule violations

Option 3: Separate validation pass

Create dedicated XML validator:

  • Runs before or after parsing
  • Uses XML schema/schematron-style checks
  • Independent of Invoice struct validation

Considerations

  • Performance: Structure validation adds overhead
  • Error reporting: Need clear messages with XML location
  • Backward compatibility: Should not break existing EN 16931 validation
  • Profile-specific: Only apply for PEPPOL profile validation

Acceptance Criteria

  • PEPPOL-EN16931-R008 implemented and tested
  • Empty element detection works for all cases (empty, whitespace, newlines)
  • Clear error messages with element path/location
  • Test coverage for valid and invalid cases
  • Performance impact documented/acceptable
  • Only runs when using ValidatePEPPOL() or --profile peppol

References

Related

Part of #24 (PEPPOL BIS Billing 3.0 support)
Depends on #32

Metadata

Metadata

Assignees

No one assigned

    Labels

    PEPPOLPEPPOL BIS Billing 3.0 validation

    Fields

    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions