From 2b1c3cc37c5ee3385190e6d2f915733b6abb7374 Mon Sep 17 00:00:00 2001 From: kim Date: Wed, 25 Jan 2012 23:10:56 +0000 Subject: [PATCH] Add script to test XPath expressions (requires xmlstarlet) git-svn-id: svn+ssh://idea.nguyen.vg/svn/sxsi/trunk/xpathcomp@1191 3cdefd35-fc62-479d-8e8d-bae585ffb9ca --- tests/scripts/xpath.sh | 46 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100755 tests/scripts/xpath.sh diff --git a/tests/scripts/xpath.sh b/tests/scripts/xpath.sh new file mode 100755 index 0000000..abb32b4 --- /dev/null +++ b/tests/scripts/xpath.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +COUNT=0 +QUERY="" +FILE="" + +function usage { + echo "usage: $0 [options] " + echo "options:" + echo "-c counting mode" + echo "-h display this help" +} + +for i in "$@" +do + if [ "$i" == "-h" ] + then + usage + exit 0 + elif [ "$i" == "-c" ] + then + COUNT=1 + continue + elif [ "$QUERY" == "" ] + then + QUERY="$i" + continue + else + FILE="$i" + fi +done + +if [ -z "$FILE" ] +then + echo "error: missing filename" + usage + exit 1 +fi + + +if [ "$COUNT" == "0" ] +then + xmlstarlet sel -t -m "$QUERY" -c . -n "$FILE" +else + xmlstarlet sel -t -v "count($QUERY)" "$FILE" +fi -- 2.17.1