pax.XRechnung.NET 0.3.0

dotnet add package pax.XRechnung.NET --version 0.3.0
                    
NuGet\Install-Package pax.XRechnung.NET -Version 0.3.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="pax.XRechnung.NET" Version="0.3.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="pax.XRechnung.NET" Version="0.3.0" />
                    
Directory.Packages.props
<PackageReference Include="pax.XRechnung.NET" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add pax.XRechnung.NET --version 0.3.0
                    
#r "nuget: pax.XRechnung.NET, 0.3.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=pax.XRechnung.NET&version=0.3.0
                    
Install pax.XRechnung.NET as a Cake Addin
#tool nuget:?package=pax.XRechnung.NET&version=0.3.0
                    
Install pax.XRechnung.NET as a Cake Tool

NuGet Version .NET

Introduction

pax.XRechnung.NET is a .NET library that helps validate, map, and generate XRechnung XML invoices, following specification 3.0.2.

Features

  • Validation: Ensure XML invoices conform to XRechnung 3.0.2 schema and Schematron rules.
  • 🔁 Mapping: Convert XML invoices into strongly typed DTOs.
  • 🧾 Generation: Create compliant XML invoices from C# objects.

Getting started

Installation

dotnet add package pax.XRechnung.NET

Usage

Validate XML schema

    var xmlText = "<Invoice>...</invoice>";
    var serializer = new XmlSerializer(typeof(XmlInvoice));
    using var stream = new MemoryStream(Encoding.UTF8.GetBytes(xmlText));
    stream.Position = 0;
    var xmlInvoice = (XmlInvoice?)serializer.Deserialize(stream);
    Assert.IsNotNull(xmlInvoice);
    var validationResult = XmlInvoiceValidator.Validate(xmlInvoice);
    Assert.IsTrue(validationresult.IsValid);

Handle Sample Invoice

public static InvoiceBaseDto GetInvoiceBaseDto()
{
    return new()
    {
        GlobalTaxCategory = "S",
        GlobalTaxScheme = "VAT",
        GlobalTax = 19.0,
        Id = "1",
        IssueDate = DateTime.UtcNow,
        InvoiceTypeCode = "380",
        DocumentCurrencyCode = "EUR",
        BuyerReference = "04011000-12345-34",
        SellerParty = new PartyBaseDto()
        {
            Name = "Seller Name",
            StreetName = "Test Street",
            City = "Test City",
            PostCode = "123456",
            CountryCode = "DE",
            Telefone = "1234/54321",
            Email = "seller@example.com",
            RegistrationName = "Seller Name",
            TaxId = "DE12345678"
        },
        BuyerParty = new PartyBaseDto()
        {
            Name = "Buyer Name",
            StreetName = "Test Street",
            City = "Test City",
            PostCode = "123456",
            CountryCode = "DE",
            Telefone = "1234/54321",
            Email = "buyer@example.com",
            RegistrationName = "Buyer Name",
        },
        PaymentMeans = new PaymentMeansBaseDto()
        {
            Iban = "DE12 1234 1234 1234 1234 12",
            Bic = "BICABCDE",
            Name = "Bank Name"
        },
        PaymentMeansTypeCode = "30",
        PaymentTermsNote = "Zahlbar innerhalb 14 Tagen nach Erhalt der Rechnung.",
        PayableAmount = 119.0,
        InvoiceLines = [
            new InvoiceLineBaseDto()
            {
                Id = "1",
                Quantity = 1.0,
                QuantityCode = "HUR",
                UnitPrice = 100.0,
                Name = "Test Job"
            }
        ]
    };
}

Serialize DTO to XML

    var invoiceBaseDto = GetInvoiceBaseDto();
    var mapper = new InvoiceMapper();
    var xmlInvoice = mapper.ToXml(invoiceBaseDto);
    var xmlText = XmlInvoiceWriter.Serialize(xmlInvoice);

Validate schematron - requires Kosit validator

    var invoiceBaseDto = GetInvoiceBaseDto();
    var mapper = new InvoiceMapper();
    XmlInvoice xmlInvoice = mapper.ToXml(invoiceBaseDto);
    var result = await XmlInvoiceValidator.ValidateSchematron(xmlInvoice);
    var resultText = string.Join(Environment.NewLine, result.Validations.Select(s => $"{s.Severity}:\t{s.Message}"));
    Assert.IsTrue(result.Validations.Count == 0, resultText);
    Assert.IsTrue(result.IsValid, resultText);

The InvoiceBaseDto is designed to be easily extended see BaseDtoExtensionTests

Java Schematron Validator

Requires a running Kosit validation server. Setup: xrechnung usage

Server start: java -jar .\validationtool-1.5.0-standalone.jar -s .\scenarios.xml -r ${PWD} -D

ChangeLog

<details open="open"><summary>v0.3.0</summary>

  • Breaking Changes
  • DTO rework to be more flexible and robust.
  • InvoiceAnnotationDto now available with Required fields and CodeList validation

</details>

<details><summary>v0.2.0</summary>

  • Breaking Changes
  • Fixed/Renamed XmlInvoice properties and dependencies. All existing properties are now xml schema conform.
  • Added Kosit schematron validation. See Java Schematron Validator
  • Replaced all DTOs with InvoiceBaseDto

</details>

<details><summary>v0.1.0</summary>

  • Breaking Changes
  • Added FinancialInstitutionBranch to FinancialAccountType (XmlPaymentInstructions)
  • Seller/Buyer cleanup and reference XmlParty
  • Changed XmlAdditionalDocumentReference to XmlAdditionalDocumentReferences as list

</details>

<details><summary>v0.0.1</summary>

  • Initial release
  • Support for invoice validation and serialization
  • Partial DTO implementation

</details>

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.3.0 77 5/2/2025
0.2.1 161 4/22/2025
0.2.0 236 4/22/2025 0.2.0 is deprecated because it has critical bugs.
0.1.0 100 3/2/2025
0.0.1 135 12/22/2024