Sample code for 30+ languages & platforms
Swift

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 Swift Downloads

Swift

func chilkatTest() {
    var success: Bool = false

    // 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
    let sb1 = CkoStringBuilder()!
    success = sb1.loadFile(path: "qa_output/signedXml_1.xml", charset: "utf-8")

    // TicketBAI Sign XML Example 2
    let sb2 = CkoStringBuilder()!
    success = sb2.loadFile(path: "qa_output/signedXml_2.xml", charset: "utf-8")

    let xml = CkoXml()!
    xml.tag = "lrpficfcsgap:LROEPF140IngresosConFacturaConSGAltaPeticion"
    xml.addAttribute(name: "xmlns:lrpficfcsgap", value: "https://www.batuz.eus/fitxategiak/batuz/LROE/esquemas/LROE_PF_140_1_1_Ingresos_ConfacturaConSG_AltaPeticion_V1_0_2.xsd")
    xml.updateChildContent(tagPath: "Cabecera|Modelo", value: "140")
    xml.updateChildContent(tagPath: "Cabecera|Capitulo", value: "1")
    xml.updateChildContent(tagPath: "Cabecera|Subcapitulo", value: "1.1")
    xml.updateChildContent(tagPath: "Cabecera|Operacion", value: "A00")
    xml.updateChildContent(tagPath: "Cabecera|Version", value: "1.0")
    xml.updateChildContent(tagPath: "Cabecera|Ejercicio", value: "2022")
    xml.updateChildContent(tagPath: "Cabecera|ObligadoTributario|NIF", value: "79732487C")
    xml.updateChildContent(tagPath: "Cabecera|ObligadoTributario|ApellidosNombreRazonSocial", value: "ARRIOLA LEJARDI ANE")
    xml.updateChildContent(tagPath: "Ingresos|Ingreso|TicketBai", value: sb1.getEncoded(encoding: "base64", charset: "utf-8"))
    xml.updateChildContent(tagPath: "Ingresos|Ingreso|Renta|DetalleRenta|Epigrafe", value: "197330")
    xml.updateChildContent(tagPath: "Ingresos|Ingreso[1]|TicketBai", value: sb2.getEncoded(encoding: "base64", charset: "utf-8"))
    xml.updateChildContent(tagPath: "Ingresos|Ingreso[1]|Renta|DetalleRenta|Epigrafe", value: "197330")
    xml.updateChildContent(tagPath: "Ingresos|Ingreso[1]|Renta|DetalleRenta|IngresoAComputarIRPFDiferenteBaseImpoIVA", value: "S")
    xml.updateChildContent(tagPath: "Ingresos|Ingreso[1]|Renta|DetalleRenta|ImporteIngresoIRPF", value: "400.00")

    print("\(xml.getXml()!)")

    success = xml.save(path: "qa_output/ticketBAI_invoice.xml")

}