FirmaSAT

"Error: content type is empty" when validating XML document signed by FirmaSAT


Problem

You create a signed XML document using the SignXML function in FirmaSAT but get an error similar to this when validating:

Se presentaron los siguientes errores al validar la estructura del comprobante MIFACTURA.xml
Error:	cvc-complex-type.2.1: Element 'cfdi:Traslado' must have no character or element 
information item [children], because the types content type is empty.
XML restriction is violated/XML restriccion es violada: Element [cfdi:Traslados/cfdi:Traslado] must be empty/El elemento debe estar vacio.

Explanation

This error is not caused by FirmaSAT. It is caused by programs that post-process or "pretty-print" the XML document signed by FirmaSAT.

An empty element in XML may be represented in two ways: <tag /> or <tag></tag>. Both forms are equally valid XML.

Problems arise when subsequent formatting introduces extra white space between the <tag> and the </tag>.

Example

When FirmaSAT signs a document, it converts any empty elements like <tag /> to the form <tag></tag>. This is perfectly valid XML. For example:

<cfdi:Traslado tasa="16.00" importe="22.07" impuesto="IVA" />
→
<cfdi:Traslado tasa="16.00" importe="22.07" impuesto="IVA"></cfdi:Traslado>

This XML will validate OK.

Problems arise when the resulting XML document is re-formatted, say, like this

<cfdi:Traslados
  <cfdi:Traslado tasa="16.00" importe="22.07" impuesto="IVA">
  </cfdi:Traslado>
</cfdi:Traslados>

This will give the error

Se presentaron los siguientes errores al validar la estructura del comprobante MIFACTURA.xml
Error:	cvc-complex-type.2.1: Element 'cfdi:Traslado' must have no character or element 
information item [children], because the types content type is empty.

The extra whitespace introduced by this formatting - that is, the newline added after the <cfdi:Traslado ... > opening tag and the extra spaces or tab characters before the closing tag </cfdi:Traslado> - will cause the SAT validation program to think there is some illegal content in an element that is meant to be empty. Hence the error.

<cfdi:Traslado tasa="16.00" importe="22.07" impuesto="IVA"></cfdi:Traslado>  <!--OK-->
<cfdi:Traslado tasa="16.00" importe="22.07" impuesto="IVA">¶ <!--Error: newline = unwanted extra space-->
◊◊◊ </cfdi:Traslado> <!--Error: leading spaces-->

This error may happen if you sign and then re-format XML documents with elements like

<cfdi:DomicilioFiscal ... />
<cfdi:ExpedidoEn ... />
<cfdi:Domicilio ... />
<cfdi:Traslado ... />

with or without the cfdi: prefix.

To solve

Well, don't do that, then! Do not re-format or pretty-print the XML document output by the FirmaSAT SignXML function. And make sure your original base XML document does not have the same error before signing.

If you must do it, then use a Regex editor afterwards on your file with the global edit s|>\s+</|></|g to delete any introduced white space, or use the new EmptyElements feature (see below).

To repeat, this is not a problem caused by FirmaSAT.

EmptyElements feature in FirmaSAT

In FirmaSAT version 5.3 we added the option to output empty elements using single empty element tags <foo/> instead of default two-tag form <foo></foo> when signing an XML document.

Use the SAT_XML_EMPTYELEMTAG option with the SAT_XmlSign function in C/VB6 or the SignOptions.UseEmptyElements option with the Sat.SignXmlEx method in C#/VB.NET. Use the -y option with the SIGNXML Command.

n = SAT_SignXml(newname, fname, keyfile, password, certfile, SAT_XML_EMPTYELEMTAG);
n = Sat.SignXmlEx(newname, fname, keyfile, password, certfile, SignOptions.UseEmptyElements);
FirmaSAT SIGNXML -y -s @ -k emisor.key -p 12345678a -c emisor.cer -i cfdv33a-base.xml -o cfdv33a_new-signed.xml

The logic to produce this single-tag empty element output is much more complicated than that required for the default two-tag form. XML comments will be deleted. It may not do exactly what you want.

Contact us

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

This page first published 5 May 2012. Last updated 12 August 2020.


HTML5 Powered reload
Copyright © 2012-19 D.I. Management Services Pty Limited ABN 78 083 210 584 Australia. All rights reserved.
<www.di-mgt.com.au>   <www.cryptosys.net>

FirmaSAT Home | Search | Contact us