![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Delphi DLL) Create SOAP with multiple VeriFactu Digitally Signed Registration RecordsSee more Verifactu ExamplesCreates a SOAP message containing a multiple digitally signed invoice registration records, formatted according to the specifications for Spain's Veri*Factu system.
uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, StringBuilder, Xml; ... procedure TForm1.Button1Click(Sender: TObject); var success: Boolean; xml: HCkXml; sbXml: HCkStringBuilder; sbSignedSoap: HCkStringBuilder; begin 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 := CkXml_Create(); CkXml_putTag(xml,'soapenv:Envelope'); CkXml_AddAttribute(xml,'xmlns:soapenv','http://schemas.xmlsoap.org/soap/envelope/'); CkXml_AddAttribute(xml,'xmlns:sum','https://www2.agenciatributaria.gob.es/static_files/common/internet/dep/aplicaciones/es/aeat/tike/cont/ws/SuministroLR.xsd'); CkXml_AddAttribute(xml,'xmlns:sum1','https://www2.agenciatributaria.gob.es/static_files/common/internet/dep/aplicaciones/es/aeat/tike/cont/ws/SuministroInformacion.xsd'); CkXml_AddAttribute(xml,'xmlns:xd','http://www.w3.org/2000/09/xmldsig#'); CkXml_UpdateChildContent(xml,'soapenv:Header',''); CkXml_UpdateChildContent(xml,'soapenv:Body|sum:RegFactuSistemaFacturacion|sum:Cabecera|sum1:ObligadoEmision|sum1:NombreRazon','XYZ STORE SL'); CkXml_UpdateChildContent(xml,'soapenv:Body|sum:RegFactuSistemaFacturacion|sum:Cabecera|sum1:ObligadoEmision|sum1:NIF','B99999999'); CkXml_UpdateChildContent(xml,'soapenv:Body|sum:RegFactuSistemaFacturacion|sum:Cabecera|sum1:RemisionRequerimiento|sum1:RefRequerimiento','3333333333'); CkXml_UpdateChildContent(xml,'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. sbXml := CkStringBuilder_Create(); CkXml_GetXmlSb(xml,sbXml); // --------------------------------------------------------------------------------------------- // Load the previously signed XML containing just one signed record. sbSignedSoap := CkStringBuilder_Create(); success := CkStringBuilder_LoadFile(sbSignedSoap,'c:/temp/qa_output/signedSoapXml1.xml','utf-8'); if (success = False) then begin Memo1.Lines.Add(CkStringBuilder__lastErrorText(sbSignedSoap)); Exit; end; // Remove everything before "</sum:Cabecera>", including the "</sum:Cabecera>" CkStringBuilder_RemoveBefore(sbSignedSoap,'</sum:Cabecera>'); // Remove everything after the "</sum:RegFactuSistemaFacturacion>", including the "</sum:RegFactuSistemaFacturacion>" CkStringBuilder_RemoveAfterFinal(sbSignedSoap,'</sum:RegFactuSistemaFacturacion>'); // We now have the portion of the signed SOAP xml from <sum:RegistroFactura> to </sum:RegistroFactura> // Insert it after the </sum:Cabecera> CkStringBuilder_Prepend(sbSignedSoap,'</sum:Cabecera>'); CkStringBuilder_ReplaceFirst(sbXml,'</sum:Cabecera>',CkStringBuilder__getAsString(sbSignedSoap)); // --------------------------------------------------------------------------------------------- // Add the next signed SOAP containing a single signed record. success := CkStringBuilder_LoadFile(sbSignedSoap,'c:/temp/qa_output/signedSoapXml2.xml','utf-8'); if (success = False) then begin Memo1.Lines.Add(CkStringBuilder__lastErrorText(sbSignedSoap)); Exit; end; // Remove everything before "</sum:Cabecera>", including the "</sum:Cabecera>" CkStringBuilder_RemoveBefore(sbSignedSoap,'</sum:Cabecera>'); // Remove everything after the "</sum:RegFactuSistemaFacturacion>", including the "</sum:RegFactuSistemaFacturacion>" CkStringBuilder_RemoveAfterFinal(sbSignedSoap,'</sum:RegFactuSistemaFacturacion>'); // We now have the portion of the signed SOAP xml from <sum:RegistroFactura> to </sum:RegistroFactura> // Insert it after the </sum:Cabecera> CkStringBuilder_Prepend(sbSignedSoap,'</sum:Cabecera>'); CkStringBuilder_ReplaceFirst(sbXml,'</sum:Cabecera>',CkStringBuilder__getAsString(sbSignedSoap)); // --------------------------------------------------------------------------------------------- // Continue adding more signed records if needed. // Save the SOAP containing multiple signed records.. CkStringBuilder_WriteFile(sbXml,'c:/temp/qa_output/soap_combined.xml','utf-8',False); CkXml_Dispose(xml); CkStringBuilder_Dispose(sbXml); CkStringBuilder_Dispose(sbSignedSoap); end; |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.