CryptoSys Home > FirmaSAT > Fixing errors when signing

Fixing errors when signing


A typical question.
I get an error when I try to sign an XML document. How do I fix this?

General procedure

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.

  1. Look up the error code: Does the error code give you a clue?
  2. Check the LastError: use the Sat.LastError Method (C#) or satLastError function (VBA). This usually gives more details of the error (see the example below).
  3. Validate the XML structure (Validate XML Document) - always do this. Does this tell you that there are problems?
  4. Fix any problems with the input file and repeat.

Example

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

Clues so far

  1. Looking up the error code (-10) we have a MISSING_ERROR: "Required data not found/Datos necesarios no encontrados".
  2. Checking the LastError, we are told "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.

Next steps

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

Alternative validation

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'.

Contact us

To contact us or comment on this page, please send us a message.

[Go to top]

This page first published 1 May 2021. Last updated 27 June 2022.