Sample code for 30+ languages & platforms
Zig

Insert Signed XML as Base64 Data into Invoice XML

See more TicketBAI Examples

Demonstrates how to insert previously signed XML into another XML as base64 data.

Chilkat Zig Downloads

Zig
const std = @import("std");
const chilkat = @import("chilkat");

pub fn main(init: std.process.Init) !void {
    const alloc = init.arena.allocator();

    // We wish to create the following XML:

    // <?xml version="1.0" encoding="UTF-8" standalone="no"?><lrpficfcsgap:LROEPF140IngresosConFacturaConSGAltaPeticion xmlns:lrpficfcsgap="https://www.batuz.eus/fitxategiak/batuz/LROE/esquemas/LROE_PF_140_1_1_Ingresos_ConfacturaConSG_AltaPeticion_V1_0_2.xsd">
    //     <Cabecera>
    //         <Modelo>140</Modelo>
    //         <Capitulo>1</Capitulo>
    //         <Subcapitulo>1.1</Subcapitulo>
    //         <Operacion>A00</Operacion>
    //         <Version>1.0</Version>
    //         <Ejercicio>2022</Ejercicio>
    //         <ObligadoTributario>
    //             <NIF>79732487C</NIF>
    //             <ApellidosNombreRazonSocial>ARRIOLA LEJARDI ANE</ApellidosNombreRazonSocial>
    //         </ObligadoTributario>
    //     </Cabecera>
    //     <Ingresos>
    //         <Ingreso>
    //             <TicketBai>PD94bWw...ldEJhaT4=</TicketBai>
    //         <Renta>
    //             <DetalleRenta>
    //                 <Epigrafe>197330</Epigrafe>
    //             </DetalleRenta>
    //         </Renta>
    //     </Ingreso>
    //         <Ingreso>
    //             <TicketBai>PD94bWw...rZXRCYWk+</TicketBai>
    //         <Renta>
    //             <DetalleRenta>
    //                 <Epigrafe>197330</Epigrafe>
    //                 <IngresoAComputarIRPFDiferenteBaseImpoIVA>S</IngresoAComputarIRPFDiferenteBaseImpoIVA>
    //                 <ImporteIngresoIRPF>400.00</ImporteIngresoIRPF>
    //             </DetalleRenta>
    //         </Renta>
    //     </Ingreso>
    //     </Ingresos>
    // </lrpficfcsgap:LROEPF140IngresosConFacturaConSGAltaPeticion>

    // Use this online tool to generate code from sample XML:
    // Generate Code to Create XML

    // First get the signed XML created in these other examples
    // TicketBAI Sign XML Example 1
    const sb1 = try chilkat.StringBuilder.init();
    defer sb1.deinit();
    try sb1.loadFile("qa_output/signedXml_1.xml", "utf-8");

    // TicketBAI Sign XML Example 2
    const sb2 = try chilkat.StringBuilder.init();
    defer sb2.deinit();
    try sb2.loadFile("qa_output/signedXml_2.xml", "utf-8");

    const xml = try chilkat.Xml.init();
    defer xml.deinit();
    xml.setTag("lrpficfcsgap:LROEPF140IngresosConFacturaConSGAltaPeticion");
    xml.addAttribute("xmlns:lrpficfcsgap", "https://www.batuz.eus/fitxategiak/batuz/LROE/esquemas/LROE_PF_140_1_1_Ingresos_ConfacturaConSG_AltaPeticion_V1_0_2.xsd") catch {};
    xml.updateChildContent("Cabecera|Modelo", "140");
    xml.updateChildContent("Cabecera|Capitulo", "1");
    xml.updateChildContent("Cabecera|Subcapitulo", "1.1");
    xml.updateChildContent("Cabecera|Operacion", "A00");
    xml.updateChildContent("Cabecera|Version", "1.0");
    xml.updateChildContent("Cabecera|Ejercicio", "2022");
    xml.updateChildContent("Cabecera|ObligadoTributario|NIF", "79732487C");
    xml.updateChildContent("Cabecera|ObligadoTributario|ApellidosNombreRazonSocial", "ARRIOLA LEJARDI ANE");
    xml.updateChildContent("Ingresos|Ingreso|TicketBai", try sb1.getEncoded(alloc, "base64", "utf-8"));
    xml.updateChildContent("Ingresos|Ingreso|Renta|DetalleRenta|Epigrafe", "197330");
    xml.updateChildContent("Ingresos|Ingreso[1]|TicketBai", try sb2.getEncoded(alloc, "base64", "utf-8"));
    xml.updateChildContent("Ingresos|Ingreso[1]|Renta|DetalleRenta|Epigrafe", "197330");
    xml.updateChildContent("Ingresos|Ingreso[1]|Renta|DetalleRenta|IngresoAComputarIRPFDiferenteBaseImpoIVA", "S");
    xml.updateChildContent("Ingresos|Ingreso[1]|Renta|DetalleRenta|ImporteIngresoIRPF", "400.00");

    std.debug.print("{s}\n", .{try xml.getXml(alloc)});

    try xml.saveXml("qa_output/ticketBAI_invoice.xml");
}