Skip to content

Instantly share code, notes, and snippets.

@efim-a-efim
Last active August 29, 2015 14:00
Show Gist options
  • Save efim-a-efim/11372066 to your computer and use it in GitHub Desktop.
Save efim-a-efim/11372066 to your computer and use it in GitHub Desktop.
Bash XML simple parser
#!/bin/bash
read_dom () {
local IFS=\>
read -d \< ENTITY CONTENT
local RET=$?
TAG_NAME=${ENTITY%% *}
ATTRIBUTES=${ENTITY#* }
return $RET
}
parse_dom () {
if [[ $TAG_NAME = "foo" ]] ; then
eval local $ATTRIBUTES
echo "foo size is: $size"
elif [[ $TAG_NAME = "bar" ]] ; then
eval local $ATTRIBUTES
echo "bar type is: $type"
fi
}
while read_dom; do
parse_dom
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment