Skip to content

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

@xgwslbe

Description

@xgwslbe

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);
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions