Last active
August 29, 2015 14:00
-
-
Save efim-a-efim/11372066 to your computer and use it in GitHub Desktop.
Bash XML simple parser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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