Sample code for 30+ languages & platforms
Rust

Create SOAP with multiple VeriFactu Digitally Signed Registration Records

See more Verifactu Examples

Creates a SOAP message containing a multiple digitally signed invoice registration records, formatted according to the specifications for Spain's Veri*Factu system.

Chilkat Rust Downloads

Rust

let _ = true;

// Begin with the following SOAP XML:

// <?xml version="1.0" encoding="utf-8"?>
// <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sum="https://www2.agenciatributaria.gob.es/static_files/common/internet/dep/aplicaciones/es/aeat/tike/cont/ws/SuministroLR.xsd" xmlns:sum1="https://www2.agenciatributaria.gob.es/static_files/common/internet/dep/aplicaciones/es/aeat/tike/cont/ws/SuministroInformacion.xsd" xmlns:xd="http://www.w3.org/2000/09/xmldsig#">
//     <soapenv:Header/>
//     <soapenv:Body>
//         <sum:RegFactuSistemaFacturacion>
//             <sum:Cabecera>
//                 <sum1:ObligadoEmision>
//                     <sum1:NombreRazon>XYZ STORE SL</sum1:NombreRazon>
//                     <sum1:NIF>B99999999</sum1:NIF>
//                 </sum1:ObligadoEmision>
//                 <sum1:RemisionRequerimiento>
//                     <sum1:RefRequerimiento>3333333333</sum1:RefRequerimiento>
//                     <sum1:FinRequerimiento>S</sum1:FinRequerimiento>
//                 </sum1:RemisionRequerimiento>
//             </sum:Cabecera>
// 
//         </sum:RegFactuSistemaFacturacion>
//     </soapenv:Body>
// </soapenv:Envelope>

let xml = chilkat::Xml::new();
xml.set_tag("soapenv:Envelope");
let _ = xml.add_attribute("xmlns:soapenv", "http://schemas.xmlsoap.org/soap/envelope/");
let _ = xml.add_attribute("xmlns:sum", "https://www2.agenciatributaria.gob.es/static_files/common/internet/dep/aplicaciones/es/aeat/tike/cont/ws/SuministroLR.xsd");
let _ = xml.add_attribute("xmlns:sum1", "https://www2.agenciatributaria.gob.es/static_files/common/internet/dep/aplicaciones/es/aeat/tike/cont/ws/SuministroInformacion.xsd");
let _ = xml.add_attribute("xmlns:xd", "http://www.w3.org/2000/09/xmldsig#");
xml.update_child_content("soapenv:Header", "");
xml.update_child_content("soapenv:Body|sum:RegFactuSistemaFacturacion|sum:Cabecera|sum1:ObligadoEmision|sum1:NombreRazon", "XYZ STORE SL");
xml.update_child_content("soapenv:Body|sum:RegFactuSistemaFacturacion|sum:Cabecera|sum1:ObligadoEmision|sum1:NIF", "B99999999");
xml.update_child_content("soapenv:Body|sum:RegFactuSistemaFacturacion|sum:Cabecera|sum1:RemisionRequerimiento|sum1:RefRequerimiento", "3333333333");
xml.update_child_content("soapenv:Body|sum:RegFactuSistemaFacturacion|sum:Cabecera|sum1:RemisionRequerimiento|sum1:FinRequerimiento", "S");

// Prior to this code, we created N signed SOAP messages, each containing a single signed record.
// Load each of these signed SOAP messages into a StringBuilder and insert after the "</sum:Cabecera>"
// Note: We must NOT use Chilkat.Xml for this.  We must do string operations using Chilkat StringBuilder to prevent whitespace or formatting modifications which would break the signatures.

let sb_xml = chilkat::StringBuilder::new();
let _ = xml.get_xml_sb(&sb_xml);

// ---------------------------------------------------------------------------------------------
// Load the previously signed XML containing just one signed record.
let sb_signed_soap = chilkat::StringBuilder::new();
if sb_signed_soap.load_file("c:/temp/qa_output/signedSoapXml1.xml", "utf-8").is_err() {
    println!("{}", sb_signed_soap.last_error_text());
    return;
}

// Remove everything before "</sum:Cabecera>", including the "</sum:Cabecera>"
let _ = sb_signed_soap.remove_before("</sum:Cabecera>");

// Remove everything after the "</sum:RegFactuSistemaFacturacion>", including the "</sum:RegFactuSistemaFacturacion>"
let _ = sb_signed_soap.remove_after_final("</sum:RegFactuSistemaFacturacion>");

// We now have the portion of the signed SOAP xml from <sum:RegistroFactura> to </sum:RegistroFactura>
// Insert it after the </sum:Cabecera>
let _ = sb_signed_soap.prepend("</sum:Cabecera>");
let _ = sb_xml.replace_first("</sum:Cabecera>", &sb_signed_soap.get_as_string().unwrap_or_default());

// ---------------------------------------------------------------------------------------------
// Add the next signed SOAP containing a single signed record.
if sb_signed_soap.load_file("c:/temp/qa_output/signedSoapXml2.xml", "utf-8").is_err() {
    println!("{}", sb_signed_soap.last_error_text());
    return;
}

// Remove everything before "</sum:Cabecera>", including the "</sum:Cabecera>"
let _ = sb_signed_soap.remove_before("</sum:Cabecera>");

// Remove everything after the "</sum:RegFactuSistemaFacturacion>", including the "</sum:RegFactuSistemaFacturacion>"
let _ = sb_signed_soap.remove_after_final("</sum:RegFactuSistemaFacturacion>");

// We now have the portion of the signed SOAP xml from <sum:RegistroFactura> to </sum:RegistroFactura>
// Insert it after the </sum:Cabecera>
let _ = sb_signed_soap.prepend("</sum:Cabecera>");
let _ = sb_xml.replace_first("</sum:Cabecera>", &sb_signed_soap.get_as_string().unwrap_or_default());

// ---------------------------------------------------------------------------------------------
// Continue adding more signed records if needed.

// Save the SOAP containing multiple signed records..
let _ = sb_xml.write_file("c:/temp/qa_output/soap_combined.xml", "utf-8", false);