-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify formatting of XML and XSD files (#114)
Also fixes a bug where a *.tmp file was committed by Travis CI if a parsing error was encountered during linting
- Loading branch information
1 parent
78ad22d
commit b9f5fb1
Showing
1 changed file
with
21 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
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 |