Invoice Validation¶
Validation workflows for UBL invoices and schema checks.
Example¶
pub fn main() {
use fatoora_core::config::{Config, EnvironmentType};
use fatoora_core::invoice::validation::validate_xml_invoice_from_str;
// Doc example: validate XML against the bundled schema.
let invoice_xml_path = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
.join("tests/fixtures/invoices/sample-simplified-invoice.xml");
let config = Config::new(EnvironmentType::NonProduction);
let xml = std::fs::read_to_string(&invoice_xml_path).expect("read invoice xml");
validate_xml_invoice_from_str(&xml, &config).expect("validate invoice");
}
from fatoora.config import Config
from fatoora.validation import validate_xml_str
# invoice_xml_path = "path/to/invoice.xml"
config = Config()
xml = invoice_xml_path.read_text(encoding="utf-8")
result = validate_xml_str(config, xml)
assert result is True
#include "fatoora/config.h"
#include "fatoora/validation.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#ifndef FATOORA_DOC_INVOICE_XML
#define FATOORA_DOC_INVOICE_XML "path/to/invoice.xml"
#endif
static char *read_file(const char *path);
int main(void) {
const char *invoice_xml_path = FATOORA_DOC_INVOICE_XML;
char *xml_cstr = read_file(invoice_xml_path);
if (!xml_cstr) {
/* handle error */
return 1;
}
struct FfiConfig *config = fatoora_config_new(FfiEnvironment_NonProduction);
/* invoice_xml_path = "path/to/invoice.xml" */
struct FfiResult_bool result = fatoora_validate_xml_str(config, xml_cstr);
if (!result.ok) {
/* handle error */
return 1;
}
assert(result.value);
free(xml_cstr);
fatoora_config_free(config);
return 0;
}
Notes¶
- Validation uses the bundled UBL schema at
assets/schemas/UBL2.1/xsd/maindoc/UBL-Invoice-2.1.xsd. - The environment only affects validation if you choose a different schema per environment.
See also: Invoice Validation Reference