Hi
Is it possible to parse a posted xml data from a remote server in unix shell script. if so how to do that? and i need to give this script path in the push url (in remote server) . how to do this?
I have tried this in asp but could not succeed....so am trying in shell scripting...the thread opened in asp forum is available in this link Parsing XML data - ASP Free
Here a little script i commited yesterday for personal use.
XmlRead () { # [1:(-v:verbose)] 2:branch to explore 3:Tag de fin
ReadTag () {
read L || return 1
T=$(echo ${L%%>*>} | sed -e 's/[<>]//g' -e 's/:/_/g')
}
[ -n "$3" ] && OPT="$1" && shift
local T=""
local V=""
while ReadTag
do
[[ $T = $2 ]] && break
[[ $T != $1 ]] && continue
[ "$OPT" = "-v" ] && echo "Tag: $T"
while ReadTag
do
[[ $T = "/$1" ]] && break
V=$(echo $L | sed s/"<[^>]*>"/""/g)
if [[ -n "$V" ]]
then eval "$T=\"$V\""
[ "$OPT" = "-v" ] && echo "$T=$V"
else [ "$OPT" = "-v" ] && echo "Tag: $T"
fi
done
[ "$OPT" = "-v" ] && echos 50 "-"
return 0
done
return 1
}
The script is called with following parameters :
1: -v to verbose, for testing and debugging purposes, outputs the variable names and values
2:subtree to explore i.e "data" will parse everithing in the subtree beginning with <data> and ending with </data>
3:endtag : permits to exit before the end of parsed file
the function returns false if EOF or endtag is reached.
possible usage
while ReadXml -v "data" "endofdata"
do
something
...
done < $XmlFile