33
44# Introduction
55
6- ` pax.XRechnung.NET ` is a .NET library for validating and mapping [ XRechnung] ( https://xeinkauf.de/xrechnung/ ) XML invoices based on [ specification 3.0.2] ( https://xeinkauf.de/app/uploads/2024/07/302-XRechnung-2024-06-20.pdf ) .
6+ ** pax.XRechnung.NET** is a .NET library that helps validate, map, and generate [ XRechnung] ( https://xeinkauf.de/xrechnung/ ) XML invoices, following [ specification 3.0.2] ( https://xeinkauf.de/app/uploads/2024/07/302-XRechnung-2024-06-20.pdf ) .
77
88## Features
9- - Validate XRechnung XML invoices
10- - Map XML invoices to DTOs for easier manipulation
11- - Generate compliant XML invoices from structured DTOs
9+ - ✅ ** Validation** : Ensure XML invoices conform to XRechnung 3.0.2 schema and Schematron rules.
10+ - 🔁 ** Mapping** : Convert XML invoices into strongly typed DTOs.
11+ - 🧾 ** Generation** : Create compliant XML invoices from C# objects.
12+
1213
1314## Getting started
1415
@@ -20,78 +21,91 @@ dotnet add package pax.XRechnung.NET
2021
2122## Usage
2223
24+ ** Validate XML schema**
25+ ``` csharp
26+ var xmlText = " <Invoice>...</invoice>" ;
27+ var serializer = new XmlSerializer (typeof (XmlInvoice ));
28+ using var stream = new MemoryStream (Encoding .UTF8 .GetBytes (xmlText ));
29+ stream .Position = 0 ;
30+ var xmlInvoice = (XmlInvoice ?)serializer .Deserialize (stream );
31+ Assert .IsNotNull (xmlInvoice );
32+ var validationResult = XmlInvoiceValidator .Validate (xmlInvoice );
33+ Assert .IsTrue (validationresult .IsValid );
34+ ```
35+
2336### Handle Sample Invoice
2437``` csharp
25- public static InvoiceBaseDto GetInvoiceBaseDto ()
38+ public static InvoiceBaseDto GetInvoiceBaseDto ()
39+ {
40+ return new ()
2641 {
27- return new ()
42+ GlobalTaxCategory = " S" ,
43+ GlobalTaxScheme = " VAT" ,
44+ GlobalTax = 19 . 0 ,
45+ Id = " 1" ,
46+ IssueDate = DateTime .UtcNow ,
47+ InvoiceTypeCode = " 380" ,
48+ DocumentCurrencyCode = " EUR" ,
49+ BuyerReference = " 04011000-12345-34" ,
50+ SellerParty = new PartyBaseDto ()
2851 {
29- GlobalTaxCategory = " S " ,
30- GlobalTaxScheme = " VAT " ,
31- GlobalTax = 19 . 0 ,
32- Id = " 1 " ,
33- IssueDate = DateTime . UtcNow ,
34- InvoiceTypeCode = " 380 " ,
35- DocumentCurrencyCode = " EUR " ,
36- BuyerReference = " 04011000-12345-34 " ,
37- SellerParty = new ()
38- {
39- Name = " Seller Name " ,
40- StreetName = " Test Street " ,
41- City = " Test City " ,
42- PostCode = " 123456 " ,
43- CountryCode = " DE " ,
44- Telefone = " 1234/54321 " ,
45- Email = " seller@example.com " ,
46- RegistrationName = " Seller Name " ,
47- TaxId = " DE12345678 "
48- } ,
49- BuyerParty = new ()
50- {
51- Name = " Buyer Name " ,
52- StreetName = " Test Street " ,
53- City = " Test City " ,
54- PostCode = " 123456 " ,
55- CountryCode = " DE " ,
56- Telefone = " 1234/54321 " ,
57- Email = " buyer@example.com " ,
58- RegistrationName = " Buyer Name " ,
59- },
60- PaymentMeans = new ()
52+ Name = " Seller Name " ,
53+ StreetName = " Test Street " ,
54+ City = " Test City " ,
55+ PostCode = " 123456 " ,
56+ CountryCode = " DE " ,
57+ Telefone = " 1234/54321 " ,
58+ Email = " seller@example.com " ,
59+ RegistrationName = " Seller Name " ,
60+ TaxId = " DE12345678 "
61+ },
62+ BuyerParty = new PartyBaseDto ()
63+ {
64+ Name = " Buyer Name " ,
65+ StreetName = " Test Street " ,
66+ City = " Test City " ,
67+ PostCode = " 123456 " ,
68+ CountryCode = " DE " ,
69+ Telefone = " 1234/54321 " ,
70+ Email = " buyer@example.com " ,
71+ RegistrationName = " Buyer Name " ,
72+ },
73+ PaymentMeans = new PaymentMeansBaseDto ()
74+ {
75+ Iban = " DE12 1234 1234 1234 1234 12 " ,
76+ Bic = " BICABCDE " ,
77+ Name = " Bank Name "
78+ } ,
79+ PaymentMeansTypeCode = " 30 " ,
80+ PaymentTermsNote = " Zahlbar innerhalb 14 Tagen nach Erhalt der Rechnung. " ,
81+ PayableAmount = 119 . 0 ,
82+ InvoiceLines = [
83+ new InvoiceLineBaseDto ()
6184 {
62- Iban = " DE12 1234 1234 1234 1234 12" ,
63- Bic = " BICABCDE" ,
64- Name = " Bank Name"
65- },
66- PaymentMeansTypeCode = " 30" ,
67- PaymentTermsNote = " Zahlbar innerhalb 14 Tagen nach Erhalt der Rechnung." ,
68- PayableAmount = 119 . 0 ,
69- InvoiceLines = [
70- new ()
71- {
72- Id = " 1" ,
73- Quantity = 1 . 0 ,
74- QuantityCode = " HUR" ,
75- UnitPrice = 100 . 0 ,
76- Name = " Test Job"
77- }
78- ]
79- };
80- }
85+ Id = " 1" ,
86+ Quantity = 1 . 0 ,
87+ QuantityCode = " HUR" ,
88+ UnitPrice = 100 . 0 ,
89+ Name = " Test Job"
90+ }
91+ ]
92+ };
93+ }
8194```
82- ** Validate xml schema**
95+
96+ ** Serialize DTO to XML**
8397``` csharp
8498 var invoiceBaseDto = GetInvoiceBaseDto ();
85- var mapper = new InvoiceMapper < InvoiceBaseDto > ();
99+ var mapper = new InvoiceMapper ();
86100 var xmlInvoice = mapper .ToXml (invoiceBaseDto );
87- var result = XmlInvoiceValidator .Validate (xmlInvoice );
88- Assert .IsTrue (result .IsValid );
101+ var xmlText = XmlInvoiceWriter .Serialize (xmlInvoice );
89102```
103+
90104** Validate schematron - requires [ Kosit validator] ( #java-schematron-validator ) **
91105``` csharp
92106 var invoiceBaseDto = GetInvoiceBaseDto ();
93- InvoiceMapper < InvoiceBaseDto > invoiceMapper = new ();
94- XmlInvoice xmlInvoice = invoiceMapper .ToXml (invoiceBaseDto );
107+ var mapper = new InvoiceMapper ();
108+ XmlInvoice xmlInvoice = mapper .ToXml (invoiceBaseDto );
95109 var result = await XmlInvoiceValidator .ValidateSchematron (xmlInvoice );
96110 var resultText = string .Join (Environment .NewLine , result .Validations .Select (s => $" {s .Severity }:\t {s .Message }" ));
97111 Assert .IsTrue (result .Validations .Count == 0 , resultText );
@@ -107,7 +121,15 @@ Server start:
107121
108122# ChangeLog
109123
110- <details open =" open " ><summary >v0.2.0</summary >
124+ <details open =" open " ><summary >v0.3.0</summary >
125+
126+ > - ** Breaking Changes**
127+ > - DTO rework to be more flexible and robust.
128+ > - InvoiceAnnotationDto now available with Required fields and CodeList validation
129+
130+ </details >
131+
132+ <details ><summary >v0.2.0</summary >
111133
112134> - ** Breaking Changes**
113135> - Fixed/Renamed XmlInvoice properties and dependencies. All existing properties are now xml schema conform.
0 commit comments