parseXmlFile.sh
创新互联主要从事成都网站设计、成都网站制作、外贸网站建设、网页设计、企业做网站、公司建网站等业务。立足成都服务城中,十年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:13518219792
#!/bin/bash
Usage()
{
echo "Usage: ./parseXmlFile.sh
exit 1
}
list_all_entity()
{
local IFS=\>
while read -d \< ENTITY CONTENT
do
echo $ENTITY
done < $1
}
list_all_content()
{
local IFS=\>
while read -d \< ENTITY CONTENT
do
echo $CONTENT
done < $1
}
list_all_tag_name()
{
local IFS=\>
while read -d \< ENTITY CONTENT
do
TAG_NAME=${ENTITY%% *}
echo $TAG_NAME
done < $1
}
list_all_attributes()
{
local IFS=\>
while read -d \< ENTITY CONTENT
do
ATTRIBUTES=${ENTITY#* *}
echo $ATTRIBUTES
done < $1
}
getattr()
{
ATTR_PAIR=${1#*$2=\"}
echo "${ATTR_PAIR%%\"*}"
}
get_attributes_value()
{
local IFS=\>
while read -d \< ENTITY CONTENT
do
TAG_NAME=${ENTITY%% *}
ATTRIBUTES=${ENTITY#* *}
if [[ $TAG_NAME == $2 ]]
then
value=`getattr ${ATTRIBUTES} ${3}`
echo $value
fi
done < $1
}
get_content_value()
{
local IFS=\>
while read -d \< ENTITY CONTENT
do
TAG_NAME=${ENTITY%% *}
if [[ $TAG_NAME == $2 ]]
then
echo $CONTENT
fi
done < $1
}
#main in this shell
if [ $# -ne 1 ]
then
Usage
fi
if [ ! -f $1 ]
then
echo "fail to load data from file, file $1 not exist!"
exit 1
fi
list_content $1