Skip to content

Instantly share code, notes, and snippets.

@3v1n0
Last active November 30, 2021 16:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 3v1n0/977e621a640309de77fbd49b23705ad5 to your computer and use it in GitHub Desktop.
Save 3v1n0/977e621a640309de77fbd49b23705ad5 to your computer and use it in GitHub Desktop.
Linter script for the Italian electronic invoice (Fattura Elettronica)
#!/bin/bash
SCHEMA_URI="https://www.fatturapa.gov.it/export/documenti/fatturapa/v1.2.1/Schema_del_file_xml_FatturaPA_versione_1.2.1.xsd"
IMPORTED_SCHEMAS=(xmldsig-core-schema.xsd)
IMPORTED_SCHEMAS_BASE_URI="https://raw.githubusercontent.com/italia/fatturapa-testsdi/master/core/schemas/"
tmp_dir=$(mktemp -d -t fe-xml-lint-XXXXXXXXXX)
schemas=("$SCHEMA_URI")
trap "rm -r $tmp_dir" EXIT
for schema in ${IMPORTED_SCHEMAS[*]}; do
schemas+=("$IMPORTED_SCHEMAS_BASE_URI/$schema")
done;
for schema in ${schemas[*]}; do
if ! wget -P $tmp_dir -q $schema; then
echo "Schema file $schema not properly downloaded"
exit 1
fi
done
# Fix import of imported remote schemas
for schema in ${IMPORTED_SCHEMAS[*]}; do
sed -i "s,schemaLocation=['\"].*$schema['\"],schemaLocation=\"file://$tmp_dir/$schema\",g" \
$tmp_dir/$(basename $SCHEMA_URI)
done;
for input in $@; do
xmllint --noout "$input" \
--schema $tmp_dir/$(basename $SCHEMA_URI)
exit_status=$?
done
exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment