Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Attachment in XML adds unexpected XML Tags that create Validation Error (BR-55) #763

Open
xgwslbe opened this issue Mar 5, 2025 · 0 comments

Comments

@xgwslbe
Copy link

xgwslbe commented Mar 5, 2025

Hi,

Issue:

we are currently working with the latest Version 2.16.3 and try to add an attachment to an existing XRechnung (3.0.2) or Factur-X Extended (1.0.7).

If we do so, the Mustang Library adds unexpected XML Tags inside of the ApplicableHeaderTradeSettlement Tag:

<ram:InvoiceReferencedDocument>
  <ram:IssuerAssignedID/>
</ram:InvoiceReferencedDocument>

This leads to validation Errors with the Mustang Validator, because it violates the BR-55:

  • [BR-55]-Each Preceding Invoice reference (BG-3) shall contain a Preceding Invoice reference (BT-25). [ID FX-SCH-A-000182] from /xslt/ZF_232/FACTUR-X_EXTENDED.xslt)

Are we doing something wrong?

FYI: We are working with base64, because of a legacy application, I just stripped the code from the current application.

Expected behaviour:

No additional InvoiceReferencedDocument, because we attach some additional information not an invoice correction e.g.

Steps/Code to reproduce:

import java.nio.charset.StandardCharsets;
import java.text.ParseException;
import org.mustangproject.FileAttachment;
import org.mustangproject.Invoice;
import org.mustangproject.ZUGFeRD.ZUGFeRD2PullProvider;
import org.mustangproject.ZUGFeRD.ZUGFeRDInvoiceImporter;
import org.mustangproject.ZUGFeRD.Profiles;
import java.util.Base64;
import javax.xml.xpath.XPathExpressionException;

public class MustangApiApplication {
	public static void main(String[] args) throws XPathExpressionException, ParseException {
		String base64Xml = ""; // USE AN OFFICIAL FACTUR-X SAMPLE AS BASE64
		byte[] xml = Base64.getDecoder().decode(base64Xml);
		String profile = "Extended";

		// Attach additional files to XML
		ZUGFeRDInvoiceImporter importer = new ZUGFeRDInvoiceImporter();
		importer.fromXML(new String(xml, StandardCharsets.UTF_8));
		Invoice invoice = importer.extractInvoice();

		FileAttachment attachment = new FileAttachment("attachment.txt", "text/plain", "Attachment",
				Base64.getDecoder().decode("RGFzIGlzdCBlaW4gVGVzdA=="));
		attachment.setDescription("Attachment");
		invoice.embedFileInXML(attachment);

		ZUGFeRD2PullProvider zf2p = new ZUGFeRD2PullProvider();

		zf2p.setProfile(Profiles.getByName(profile));
		zf2p.generateXML(invoice);
		byte[] xmlWithAttachments = zf2p.getXML();

		// Return result
		String base64XmlWithAttachments = new String(Base64.getEncoder().encode(xmlWithAttachments),
				StandardCharsets.UTF_8);

		System.out.println(base64XmlWithAttachments);
	}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant