Handling electronic invoices at scale—whether Peppol UBL 2.1, EN 16931, or local tax authority XML schemas—usually means uploading sensitive financial documents to a third-party backend. Every vendor uses slightly different XML namespaces (cbc:, cac:, ns2:, or unprefixed tags), making brittle XPath queries break on real-world supplier files.

Here is the architecture behind our 100% client-side XML E-Invoice & Peppol UBL parser and auditor, built with Vanilla ES Modules and deployed at the edge on Cloudflare Workers—with zero server uploads.

1. Namespace-Agnostic Tag Extraction

Instead of hardcoding strict XML namespace prefixes, we normalize extraction across arbitrary vendor prefixes using a lightweight namespace-agnostic pattern combined with DOMParser fallback:

const tagPattern = (tagName) => new RegExp(`<(?:[a-zA-Z0-9_]+:)?${tagName}\\b[^>]*>([\\s\\S]*?)</(?:[a-zA-Z0-9_]+:)?${tagName}>`, 'i'); export function extractTag(xml, tagName) { const match = xml.match(tagPattern(tagName)); return match ? match[1].trim() : ''; } 

This cleanly resolves fields like InvoiceNumber / ID, IssueDate, SupplierTaxID, TaxExclusiveAmount, TaxAmount, and PayableAmount across both Peppol UBL 2.1 documents and regional e-invoice XML formats without shipping megabytes of XML dependencies.

2. Deterministic 5-Rule Tax Math & Duplicate Auditing

Once parsed in memory, every batch runs through a 5-rule verification pipeline before export:

  1. Line-Item Sum Check: Verifies sum(lineNetAmounts) matches header TaxExclusiveAmount within rounding tolerance.
  2. VAT Rate Consistency: Checks TaxAmount / TaxExclusiveAmount against valid statutory brackets (0%, 5%, 8%, 10%, or custom EU/VAT rates).
  3. Grand Total Reconciliation: Validates TaxExclusiveAmount + TaxAmount === PayableAmount.
  4. Duplicate Invoice Fingerprinting: Flags collisions on (SupplierTaxID + InvoiceSeries + InvoiceNumber) across multi-file drops.
  5. Required Tax Metadata Guard: Catches missing buyer/supplier tax IDs or malformed ISO dates before ERP import.

3. UTF-8 BOM CSV Export for Excel

A common pitfall with browser CSV exports is garbled UTF-8 characters when accountants double-click the file in Microsoft Excel. Prepending the UTF-8 Byte Order Mark (\uFEFF) and escaping RFC 4180 quotes guarantees instant, clean spreadsheet imports across Windows and macOS.

Live Demos & Full Source Bundle

All parsing happens strictly inside your browser tab—sensitive supplier prices, tax IDs, and margins never leave your device.