Skip to main content

validate_xml

Function validate_xml 

Source
pub fn validate_xml(xml: &str) -> Result<(), FiscalError>
Expand description

Validate an NF-e XML string by checking for the presence of required tags.

This is a lightweight structural validator that checks for mandatory tags in the NF-e/NFC-e XML. It does not perform full XSD schema validation (which would require shipping XSD files and a full XML schema parser), but covers the most common errors that would cause SEFAZ rejection.

Validated items:

  • Required root structure (<NFe>, <infNFe>)
  • Required <ide> fields (cUF, cNF, natOp, mod, serie, nNF, dhEmi, tpNF, etc.)
  • Required <emit> fields (CNPJ/CPF, xNome, enderEmit, IE, CRT)
  • Required <det> with at least one item
  • Required <total> / <ICMSTot>
  • Required <transp> and <pag>
  • Access key format (44 digits)

§Errors

Returns [FiscalError::XmlParsing] with a description of all missing tags.

§Examples

use fiscal_core::xml_utils::validate_xml;
let xml = "<NFe><infNFe>...</infNFe></NFe>";
// Will return an error listing all missing required tags
assert!(validate_xml(xml).is_err());