Last active
November 30, 2021 16:33
-
-
Save 3v1n0/977e621a640309de77fbd49b23705ad5 to your computer and use it in GitHub Desktop.
Linter script for the Italian electronic invoice (Fattura Elettronica)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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