From 2617eae524d85f67d66e26d245be6c161e103ab6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20Gro=C3=9Fberndt?= Date: Tue, 10 Nov 2020 22:28:43 +0100 Subject: [PATCH] Simplify formatting of XML and XSD files --- .travis/xmllint-check.sh | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/.travis/xmllint-check.sh b/.travis/xmllint-check.sh index df055dcb7..a66afde5b 100644 --- a/.travis/xmllint-check.sh +++ b/.travis/xmllint-check.sh @@ -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