Sample code for 30+ languages & platforms
Android™

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 Android™ Downloads

Android™
// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;

import android.app.Activity;
import com.chilkatsoft.*;

import android.widget.TextView;
import android.os.Bundle;

public class SimpleActivity extends Activity {

  private static final String TAG = "Chilkat";

  // Called when the activity is first created.
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    boolean success = 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
    CkStringBuilder sb1 = new CkStringBuilder();
    success = sb1.LoadFile("qa_output/signedXml_1.xml","utf-8");

    // TicketBAI Sign XML Example 2
    CkStringBuilder sb2 = new CkStringBuilder();
    success = sb2.LoadFile("qa_output/signedXml_2.xml","utf-8");

    CkXml xml = new CkXml();
    xml.put_Tag("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");
    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",sb1.getEncoded("base64","utf-8"));
    xml.UpdateChildContent("Ingresos|Ingreso|Renta|DetalleRenta|Epigrafe","197330");
    xml.UpdateChildContent("Ingresos|Ingreso[1]|TicketBai",sb2.getEncoded("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");

    Log.i(TAG, xml.getXml());

    success = xml.SaveXml("qa_output/ticketBAI_invoice.xml");

  }

  static {
      System.loadLibrary("chilkat");

      // Note: If the incorrect library name is passed to System.loadLibrary,
      // then you will see the following error message at application startup:
      //"The application <your-application-name> has stopped unexpectedly. Please try again."
  }
}