Skip to content

Instantly share code, notes, and snippets.

@gpoole
Last active August 29, 2015 14:05
Show Gist options
  • Save gpoole/96463780a82fb3ab4314 to your computer and use it in GitHub Desktop.
Save gpoole/96463780a82fb3ab4314 to your computer and use it in GitHub Desktop.
Take an xpath and a file, run the xpath query and output nicely formatted result XML to the terminal or a file
#!/bin/bash
if [ -z "$2" ]; then
echo "Usage: `basename $0` XPATH FILE"
exit 1
fi
# For terminal output colourise it too, but for file output just tidy it up
if [ -t 1 ]; then
xmllint --xpath "$1" $2 | tidy -indent -xml -q | pygmentize -lxml
else
xmllint --xpath "$1" $2 | tidy -indent -xml -q
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment