您好,登錄后才能下訂單哦!
parseXmlFile.sh
#!/bin/bash
Usage()
{
echo "Usage: ./parseXmlFile.sh <target.xml>"
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
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。