Sample code for 30+ languages & platforms
DataFlex

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

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoSb1
    Handle hoSb2
    Handle hoXml
    String sTemp1

    Move False To iSuccess

    // 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
    Get Create (RefClass(cComChilkatStringBuilder)) To hoSb1
    If (Not(IsComObjectCreated(hoSb1))) Begin
        Send CreateComObject of hoSb1
    End
    Get ComLoadFile Of hoSb1 "qa_output/signedXml_1.xml" "utf-8" To iSuccess

    // TicketBAI Sign XML Example 2
    Get Create (RefClass(cComChilkatStringBuilder)) To hoSb2
    If (Not(IsComObjectCreated(hoSb2))) Begin
        Send CreateComObject of hoSb2
    End
    Get ComLoadFile Of hoSb2 "qa_output/signedXml_2.xml" "utf-8" To iSuccess

    Get Create (RefClass(cComChilkatXml)) To hoXml
    If (Not(IsComObjectCreated(hoXml))) Begin
        Send CreateComObject of hoXml
    End
    Set ComTag Of hoXml To "lrpficfcsgap:LROEPF140IngresosConFacturaConSGAltaPeticion"
    Get ComAddAttribute Of hoXml "xmlns:lrpficfcsgap" "https://www.batuz.eus/fitxategiak/batuz/LROE/esquemas/LROE_PF_140_1_1_Ingresos_ConfacturaConSG_AltaPeticion_V1_0_2.xsd" To iSuccess
    Send ComUpdateChildContent To hoXml "Cabecera|Modelo" "140"
    Send ComUpdateChildContent To hoXml "Cabecera|Capitulo" "1"
    Send ComUpdateChildContent To hoXml "Cabecera|Subcapitulo" "1.1"
    Send ComUpdateChildContent To hoXml "Cabecera|Operacion" "A00"
    Send ComUpdateChildContent To hoXml "Cabecera|Version" "1.0"
    Send ComUpdateChildContent To hoXml "Cabecera|Ejercicio" "2022"
    Send ComUpdateChildContent To hoXml "Cabecera|ObligadoTributario|NIF" "79732487C"
    Send ComUpdateChildContent To hoXml "Cabecera|ObligadoTributario|ApellidosNombreRazonSocial" "ARRIOLA LEJARDI ANE"
    Get ComGetEncoded Of hoSb1 "base64" "utf-8" To sTemp1
    Send ComUpdateChildContent To hoXml "Ingresos|Ingreso|TicketBai" sTemp1
    Send ComUpdateChildContent To hoXml "Ingresos|Ingreso|Renta|DetalleRenta|Epigrafe" "197330"
    Get ComGetEncoded Of hoSb2 "base64" "utf-8" To sTemp1
    Send ComUpdateChildContent To hoXml "Ingresos|Ingreso[1]|TicketBai" sTemp1
    Send ComUpdateChildContent To hoXml "Ingresos|Ingreso[1]|Renta|DetalleRenta|Epigrafe" "197330"
    Send ComUpdateChildContent To hoXml "Ingresos|Ingreso[1]|Renta|DetalleRenta|IngresoAComputarIRPFDiferenteBaseImpoIVA" "S"
    Send ComUpdateChildContent To hoXml "Ingresos|Ingreso[1]|Renta|DetalleRenta|ImporteIngresoIRPF" "400.00"

    Get ComGetXml Of hoXml To sTemp1
    Showln sTemp1

    Get ComSaveXml Of hoXml "qa_output/ticketBAI_invoice.xml" To iSuccess


End_Procedure