Sample code for 30+ languages & platforms
Unicode C

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 Unicode C Downloads

Unicode C
#include <C_CkXmlW.h>
#include <C_CkStringBuilderW.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkXmlW xml;
    HCkStringBuilderW sbXml;
    HCkStringBuilderW sbSignedSoap;

    success = FALSE;

    success = 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>

    xml = CkXmlW_Create();
    CkXmlW_putTag(xml,L"soapenv:Envelope");
    CkXmlW_AddAttribute(xml,L"xmlns:soapenv",L"http://schemas.xmlsoap.org/soap/envelope/");
    CkXmlW_AddAttribute(xml,L"xmlns:sum",L"https://www2.agenciatributaria.gob.es/static_files/common/internet/dep/aplicaciones/es/aeat/tike/cont/ws/SuministroLR.xsd");
    CkXmlW_AddAttribute(xml,L"xmlns:sum1",L"https://www2.agenciatributaria.gob.es/static_files/common/internet/dep/aplicaciones/es/aeat/tike/cont/ws/SuministroInformacion.xsd");
    CkXmlW_AddAttribute(xml,L"xmlns:xd",L"http://www.w3.org/2000/09/xmldsig#");
    CkXmlW_UpdateChildContent(xml,L"soapenv:Header",L"");
    CkXmlW_UpdateChildContent(xml,L"soapenv:Body|sum:RegFactuSistemaFacturacion|sum:Cabecera|sum1:ObligadoEmision|sum1:NombreRazon",L"XYZ STORE SL");
    CkXmlW_UpdateChildContent(xml,L"soapenv:Body|sum:RegFactuSistemaFacturacion|sum:Cabecera|sum1:ObligadoEmision|sum1:NIF",L"B99999999");
    CkXmlW_UpdateChildContent(xml,L"soapenv:Body|sum:RegFactuSistemaFacturacion|sum:Cabecera|sum1:RemisionRequerimiento|sum1:RefRequerimiento",L"3333333333");
    CkXmlW_UpdateChildContent(xml,L"soapenv:Body|sum:RegFactuSistemaFacturacion|sum:Cabecera|sum1:RemisionRequerimiento|sum1:FinRequerimiento",L"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.

    sbXml = CkStringBuilderW_Create();
    CkXmlW_GetXmlSb(xml,sbXml);

    // ---------------------------------------------------------------------------------------------
    // Load the previously signed XML containing just one signed record.
    sbSignedSoap = CkStringBuilderW_Create();
    success = CkStringBuilderW_LoadFile(sbSignedSoap,L"c:/temp/qa_output/signedSoapXml1.xml",L"utf-8");
    if (success == FALSE) {
        wprintf(L"%s\n",CkStringBuilderW_lastErrorText(sbSignedSoap));
        CkXmlW_Dispose(xml);
        CkStringBuilderW_Dispose(sbXml);
        CkStringBuilderW_Dispose(sbSignedSoap);
        return;
    }

    // Remove everything before "</sum:Cabecera>", including the "</sum:Cabecera>"
    CkStringBuilderW_RemoveBefore(sbSignedSoap,L"</sum:Cabecera>");

    // Remove everything after the "</sum:RegFactuSistemaFacturacion>", including the "</sum:RegFactuSistemaFacturacion>"
    CkStringBuilderW_RemoveAfterFinal(sbSignedSoap,L"</sum:RegFactuSistemaFacturacion>");

    // We now have the portion of the signed SOAP xml from <sum:RegistroFactura> to </sum:RegistroFactura>
    // Insert it after the </sum:Cabecera>
    CkStringBuilderW_Prepend(sbSignedSoap,L"</sum:Cabecera>");
    CkStringBuilderW_ReplaceFirst(sbXml,L"</sum:Cabecera>",CkStringBuilderW_getAsString(sbSignedSoap));

    // ---------------------------------------------------------------------------------------------
    // Add the next signed SOAP containing a single signed record.
    success = CkStringBuilderW_LoadFile(sbSignedSoap,L"c:/temp/qa_output/signedSoapXml2.xml",L"utf-8");
    if (success == FALSE) {
        wprintf(L"%s\n",CkStringBuilderW_lastErrorText(sbSignedSoap));
        CkXmlW_Dispose(xml);
        CkStringBuilderW_Dispose(sbXml);
        CkStringBuilderW_Dispose(sbSignedSoap);
        return;
    }

    // Remove everything before "</sum:Cabecera>", including the "</sum:Cabecera>"
    CkStringBuilderW_RemoveBefore(sbSignedSoap,L"</sum:Cabecera>");

    // Remove everything after the "</sum:RegFactuSistemaFacturacion>", including the "</sum:RegFactuSistemaFacturacion>"
    CkStringBuilderW_RemoveAfterFinal(sbSignedSoap,L"</sum:RegFactuSistemaFacturacion>");

    // We now have the portion of the signed SOAP xml from <sum:RegistroFactura> to </sum:RegistroFactura>
    // Insert it after the </sum:Cabecera>
    CkStringBuilderW_Prepend(sbSignedSoap,L"</sum:Cabecera>");
    CkStringBuilderW_ReplaceFirst(sbXml,L"</sum:Cabecera>",CkStringBuilderW_getAsString(sbSignedSoap));

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

    // Save the SOAP containing multiple signed records..
    CkStringBuilderW_WriteFile(sbXml,L"c:/temp/qa_output/soap_combined.xml",L"utf-8",FALSE);


    CkXmlW_Dispose(xml);
    CkStringBuilderW_Dispose(sbXml);
    CkStringBuilderW_Dispose(sbSignedSoap);

    }