Skip to content

Commit

Permalink
Simplify formatting of XML and XSD files (#114)
Browse files Browse the repository at this point in the history
Also fixes a bug where a *.tmp file was committed by Travis CI if a parsing error was encountered during linting
  • Loading branch information
sgrossberndt authored Nov 11, 2020
1 parent 78ad22d commit b9f5fb1
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions .travis/xmllint-check.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
#!/bin/bash
/usr/bin/find . -type f \( -name "*.xsd" -or -name "*.xml" \) -print0 | while read -r -d $'\0' filename; do XMLLINT_INDENT=$'\t' xmllint --encode UTF-8 --pretty 1 "${filename}" > "${filename}.pretty"; mv "${filename}.pretty" "${filename}"; grep -i -v "xmlspy" "${filename}" > "${filename}.tmp" && mv "${filename}.tmp" "${filename}"; done;
echo "finished formatting"
# The -e flag causes the script to exit as soon as one command returns a non-zero exit code
set -e

echo "Formatting XSD and XML files"

PARSING_ERROR=0
while IFS= read -r -d $'\0' filename; do
if XMLLINT_INDENT=$'\t' xmllint --encode UTF-8 --pretty 1 "${filename}" >"${filename}.pretty"; then
grep -i -v "xmlspy" "${filename}.pretty" >"${filename}"
else
PARSING_ERROR=$?
echo -e "\033[0;31mParsing of file '${filename}' failed\033[0m"
fi
rm "${filename}.pretty"
done < <(/usr/bin/find . -type f \( -name "*.xsd" -or -name "*.xml" \) -print0)

if [ ${PARSING_ERROR} -ne 0 ]; then
exit ${PARSING_ERROR}
fi
echo -e '\033[0;32mFinished formatting XSD and XML files\033[0m'

# xmllint --noout --schema OJP.xsd examples/subdirectory1/*xml examples/subdirectory2/*xml

0 comments on commit b9f5fb1

Please sign in to comment.