XSD+SCH SAT (Servicio de Administración Tributaria) · 4.0

CFDI 4.0

Mexican e-invoice (Comprobante Fiscal Digital por Internet)

The Mexican electronic invoice, with the Timbre Fiscal Digital stamp and the Pagos 2.0 payment complement

About

Every invoice in Mexico is a CFDI: an XML file signed by the issuer and stamped (timbrado) by an authorised certification provider (PAC) before it is valid. Version 4.0 has been the only accepted version since 2023.

The Complemento element only accepts elements whose schema is known, so a stamped CFDI fails against cfdv40.xsd alone. This entry loads cfdv40.xsd together with the SAT schemas of the Timbre Fiscal Digital 1.1 and the Complemento para recepción de Pagos 2.0 through a small wrapper schema by xmlvalid.com.

E-invoicing in Mexico: the rules in short and how to check an invoice →

Good to know

  • The schema checks structure, data types and the SAT catalogues it includes (catCFDI is 6 MB of code lists).
  • After the schema, xmlvalid's rules run the validations of SAT's error matrices that can be made on the file, with SAT's error codes: the subtotal, discounts and total, each line's amount and taxes within the limits of Anexo 20, the tax summary, decimals by currency, exchange rates, payment form and method, the global invoice, the receiver's regime and use of the CFDI, and for a payment receipt (P) the Pagos 2.0 rules: the fixed fields, balances, conversions by EquivalenciaDR, the taxes paid and the totals in pesos.
  • Not checked: the seal and certificate, SAT's RFC registry (names, postal codes, retention marks), limits that need the day's exchange rate or the Resolución Miscelánea (Confirmacion), and what the product catalogue requires of each line.
  • Other complements (Carta Porte, Nómina, Comercio Exterior and so on) are not included; a document that carries one is reported invalid here.
  • The examples are by xmlvalid.com and use SAT's test RFCs EKU9003173C9 and URE180429TM6: an invoice with VAT at 16% and a payment receipt for an invoice in dollars paid in pesos. Their seals, certificates and stamps are placeholders.

Files

7 files · 5.6 MB · Download all (.zip)

The validator loads all of these with their folder structure, so includes and imports resolve as published

Business rules

Schematron · run in this order

The rules run after the schema check, only when the document matches the schema, and in your browser like the schema check (with SaxonJS by Saxonica). Each finding names its rule, such as BR-CO-15, and the line it points at; each rule has a page with what it checks.

Example document

factura.xml · 1.9 KB · passes the schema and the rules

In CI and from code

The same schema by its name, cfdi-4.0, through the API.

npx @xmlvalid/cli validate "**/*.xml" --schema cfdi-4.0
- uses: xmlvalid/validate-action@v1
  with:
    files: "**/*.xml"
    schema: cfdi-4.0
    api-key: ${{ secrets.XMLVALID_API_KEY }}
curl https://xmlvalid.com/api/v1/validations \
  -H "Authorization: Bearer $XMLVALID_API_KEY" \
  -F document=@factura.xml \
  -F schema=cfdi-4.0

Free accounts get 100 API validations a month. On Pro, a URL monitor can check a published document against this schema every hour and email you when it breaks. More CI setups