Could not find any match !

XML -

Pretty print


#!/bin/bash

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# In-Place pretty printing of the supplied XML file/directory. Directories will be processed recursively while matching
# files with the suffix *.xml . This script will fail with invalid XML files.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

function format {
  echo "Pretty printing ${1} ..."
  FILE=${1}
  TFILE="${FILE}_"
  xmllint --format ${FILE} >${TFILE}
  rm ${FILE}
  mv ${TFILE} ${FILE}
  echo "... done"
}

RES=$(readlink -f ${1})

if [ -d "${RES}" ]; then
  LIST=(`find "${RES}" -name "*.xml"`)
  LENGTH=${#LIST[@]}
  for ((i=0; i<${LENGTH}; i += 1))
  do
    format "${LIST[i]}"
  done
  echo "Finished directory ${RES} !"
else
  format "${RES}"
fi