PureBasic
PureBasic
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 PureBasic Downloads
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkXml.pb"
Procedure ChilkatExample()
success.i = 0
; 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
sb1.i = CkStringBuilder::ckCreate()
If sb1.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success = CkStringBuilder::ckLoadFile(sb1,"qa_output/signedXml_1.xml","utf-8")
; TicketBAI Sign XML Example 2
sb2.i = CkStringBuilder::ckCreate()
If sb2.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success = CkStringBuilder::ckLoadFile(sb2,"qa_output/signedXml_2.xml","utf-8")
xml.i = CkXml::ckCreate()
If xml.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkXml::setCkTag(xml, "lrpficfcsgap:LROEPF140IngresosConFacturaConSGAltaPeticion")
CkXml::ckAddAttribute(xml,"xmlns:lrpficfcsgap","https://www.batuz.eus/fitxategiak/batuz/LROE/esquemas/LROE_PF_140_1_1_Ingresos_ConfacturaConSG_AltaPeticion_V1_0_2.xsd")
CkXml::ckUpdateChildContent(xml,"Cabecera|Modelo","140")
CkXml::ckUpdateChildContent(xml,"Cabecera|Capitulo","1")
CkXml::ckUpdateChildContent(xml,"Cabecera|Subcapitulo","1.1")
CkXml::ckUpdateChildContent(xml,"Cabecera|Operacion","A00")
CkXml::ckUpdateChildContent(xml,"Cabecera|Version","1.0")
CkXml::ckUpdateChildContent(xml,"Cabecera|Ejercicio","2022")
CkXml::ckUpdateChildContent(xml,"Cabecera|ObligadoTributario|NIF","79732487C")
CkXml::ckUpdateChildContent(xml,"Cabecera|ObligadoTributario|ApellidosNombreRazonSocial","ARRIOLA LEJARDI ANE")
CkXml::ckUpdateChildContent(xml,"Ingresos|Ingreso|TicketBai",CkStringBuilder::ckGetEncoded(sb1,"base64","utf-8"))
CkXml::ckUpdateChildContent(xml,"Ingresos|Ingreso|Renta|DetalleRenta|Epigrafe","197330")
CkXml::ckUpdateChildContent(xml,"Ingresos|Ingreso[1]|TicketBai",CkStringBuilder::ckGetEncoded(sb2,"base64","utf-8"))
CkXml::ckUpdateChildContent(xml,"Ingresos|Ingreso[1]|Renta|DetalleRenta|Epigrafe","197330")
CkXml::ckUpdateChildContent(xml,"Ingresos|Ingreso[1]|Renta|DetalleRenta|IngresoAComputarIRPFDiferenteBaseImpoIVA","S")
CkXml::ckUpdateChildContent(xml,"Ingresos|Ingreso[1]|Renta|DetalleRenta|ImporteIngresoIRPF","400.00")
Debug CkXml::ckGetXml(xml)
success = CkXml::ckSaveXml(xml,"qa_output/ticketBAI_invoice.xml")
CkStringBuilder::ckDispose(sb1)
CkStringBuilder::ckDispose(sb2)
CkXml::ckDispose(xml)
ProcedureReturn
EndProcedure