stephanstapel / ZUGFeRD-csharp

C# assembly for creating and reading ZUGFeRD invoices
Apache License 2.0
219 stars 116 forks source link

Export to XRechnung uses wrong encoding. #126

Closed BarthauerSoftwareGmbH closed 3 years ago

BarthauerSoftwareGmbH commented 3 years ago

Hello,

I found another small issue.

After temporarily fixing my other issue by omitting the TradeLineComments for now, we got the complain from our customer that the XRechnung is encoded as "UTF-8 BOM" instead of "UTF-8" and because of that can't be processed by them.

The Specification also states in Part 1, Chapter 5.1 that the XML file needs to be encoded as "UTF-8". (Although atleast for me it wouldnt be clear if they mean "UTF-8" only or the entirety of UTF-8 which would include UTF-8 BOM)

Johannes

stephanstapel commented 3 years ago

I haven't come across this so far. My understanding is the same as yours: UTF-8 is required and the standard does not mention anything on the flavor (googling "xrechnung utf-8 bom" doesn't lead to any valuable information).

As changing this would cause very much change for the users, would it be a viable option to write the XRechnung into to stream and write this into a UTF-8 file then?

Alpini1980 commented 3 years ago

I think the customer didn't express well to describe the problem. The generated XML's have a three byte UTF-8 BOM at the beginning of the file:

Screenshot 2020-12-09 181119

It's good decribed here: https://de.wikipedia.org/wiki/Byte_Order_Mark

"...ein BOM am String- oder Dateianfang ist erlaubt, um die Verwendung von UTF-8 als Kodierung zu kennzeichnen."

That way text editors like notepad, textpad, etc. know to use UTF-8 without reading the XML declaration.

This one may be interesting to prevent the "BOM" (it isn't really one in UTF-8 Files) written into XML-files:

https://stackoverflow.com/questions/1755958/how-can-i-remove-the-bom-from-xmltextwriter-using-c

stephanstapel commented 3 years ago

@BarthauerSoftwareGmbH : does the proposed solution work for you? If so, can we close the issue?