I get an error when I try to sign an XML document. How do I fix this?
If the XML structure of the input file is invalid, or if the input XML does not match the SAT requirements for the document, an error will occur when trying to sign. You must fix up the input XML document before continuing.
FirmaSAT XMLOK cfdv33a-badspec.xml
Here is an example input document we are trying to sign (cfdv33a-badspec.xml
).
<?xml version="1.0" encoding="UTF-8"?> <cfdi:Comprobante xmlns:cfdi="http://www.sat.gob.mx/cfd/3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sat.gob.mx/cfd/3 http://www.sat.gob.mx/sitio_internet/cfd/3/cfdv33.xsd" Version="3.3" Serie="A" Folio="123ABC" Fecha="2021-04-26T06:40:51" NoCertificado="30001000000300023708" SubTotal="0.00" Moneda="USD" TipoCambio="1.00" Total="0.00" TipoDeComprobante="T" LugarExpedicion="45079" Sello="" Certificado=""> <cfdi:Emisor Rfc="AAA010101AAA" Nombre="Esta es una demostración" RegimenFiscal="622"/> <cfdi:Receptor Rfc="BASJ600902KL9" Nombre="Juanito Bananas De la Sierra" UsoCFDI="G03"/> <cfdi:Conceptos> <!-- Missing required Importe attributes --> <cfdi:Concepto ClaveProdServ="01010101" ClaveUnidad="H87" NoIdentificacion="A00003" Cantidad="20.00" Unidad="EA" Descripcion="COSAS MISCELÁNEAS (X2)" ValorUnitario="20.06" /> <cfdi:Concepto ClaveProdServ="01010101" ClaveUnidad="H87" NoIdentificacion="A00002" Cantidad="20.00" Unidad="EA" Descripcion="COSAS MISCELÁNEAS (X11)" ValorUnitario="16.54"/> </cfdi:Conceptos> </cfdi:Comprobante>
Code using C#:
// Attempt to sign but input file does not comply with CFDi specifications int n = satSignXml("cfdv33a-out.xml", "cfdv33a-badspec.xml", "emisor.key", "12345678a", "emisor.cer"); Console.WriteLine("Error {0}: {1}", n, Sat.ErrorLookup(n)); // Error -10: Required data not found/Datos necesarios no encontrados (MISSING_ERROR) Console.WriteLine(Sat.LastError()); // Attribute 'Importe' is mandatory/Atributo es obligatorio
Alternative code using VBA:
' Attempt to sign but input file does not comply with CFDi specifications Debug.Print satSignXml("cfdv33a-signed_output.xml", "cfdv33a-badspec.xml", "emisor.key", "12345678a", "emisor.cer") ' -10 Debug.Print satErrorLookup(-10) ' Required data not found/Datos necesarios no encontrados (MISSING_ERROR) Debug.Print satLastError() ' Attribute 'Importe' is mandatory/Atributo es obligatorio
"Required data not found/Datos necesarios no encontrados"
."Attribute 'Importe' is mandatory/Atributo es obligatorio"
.Now let us check the structure of the XML document:
> FirmaSAT XMLOK cfdv33a-badspec.xml Error code -27: Invalid XML format/No valido formato XML (BAD_XML_ERROR): XML validation error/Error al validar XML: Required attribute 'Importe' missing for element 'cfdi:Concepto' (Line/numero de linea: 12) XML validation error/Error al validar XML: Required attribute 'Importe' missing for element 'cfdi:Concepto' (Line/numero de linea: 13)
So the cfdi:Concepto
elements on lines 12 and 13 are missing a required Importe
attribute.
Add the required attributes, even if they are zero, e.g. Importe="0.00"
.
Now check the fixed file:
> FirmaSAT XMLOK cfdv33a-badspec-fixed.xml OK
As an extra confirmation that the input is invalid, here is the result of using the Eclipse XML validator on the document:
cvc-complex-type.4: Attribute 'Importe' must appear on element 'cfdi:Concepto'. cvc-complex-type.4: Attribute 'Importe' must appear on element 'cfdi:Concepto'.
To contact us or comment on this page, please send us a message.
This page first published 1 May 2021. Last updated 27 June 2022.