linux 获取xml节点值,应用shell脚本读取xml的属性值和节点值

当前位置:我的异常网» XML/SOAP » 应用shell脚本读取xml的属性值和节点值

应用shell脚本读取xml的属性值和节点值

www.myexceptions.net  网友分享于:2013-11-04  浏览:300次

使用shell脚本读取xml的属性值和节点值

#FUNCRION: GetNodeValue

#DESC    : Get xmlnode value

#INPUT   : 1-XmlFilePath 2-NodeName

#OUTPUT  : nodevalue

function GetNodeValue

{

if [ $# -ne 2 ];then

echo "    error: arguments is not enough"

echo "    USAGE:            $0 XmlFilePath NodeName"

echo "    XmlFilePath       xmlfile path type[${HOME}/config/datasource/bmp-xa-ds.xml]"

echo "    NodeName          nodename type[xa-datasource-property]"

echo     e.g.:  $0 ${HOME}/config/datasource/bmp-xa-ds.xml 'xa-datasource-property name="URL"'

return

fi

CurrentTime=`date +"%Y%m%d%H%M%S"`

tmpfile="$$_$CurrentTime"

FilePath=$1

NodeName=$2

NodePre=`awk -v Node="$NodeName" 'BEGIN {split(Node,NodeAdd," ");print NodeAdd[1]}'`

FLAG=0

sed 's/>/>\n/g' $FilePath | sed 's/

do

ISFIRST=`echo $line | sed -n "/

if [ "x$ISFIRST" != "x" ]; then

FLAG=1

fi

if [ ${FLAG} -eq 1 ] ; then

echo $line >> "$tmpfile"

fi

ISSEC=`echo $line | sed -n "//"p`

if [ "x$ISSEC" != "x" ]; then

FLAG=0

fi

done

awk '{ORS=""}{print $0}' $tmpfile | awk 'BEGIN{FS=">";RS=""}{print $NF}' | sed '/^\(\s\)*$/d'

rm $tmpfile

}

#FUNCRION: GetNodeAttr

#DESC    : Get xmlnode attribute

#INPUT   : 1-XmlFilePath 2-AttrName

#OUTPUT  : node attribute

function GetNodeAttr

{

if [ $# -ne 2 ];then

echo "    error: arguments is not enough"

echo "    USAGE:            $0 XmlFilePath AttrName"

echo "    XmlFilePath       xmlfile path type[${HOME}/config/DiamBaseConfig.xml]"

echo "    AttrName          nodename type[PeerIp]"

echo "    e.g.:  $0 ${HOME}/config/DiamBaseConfig.xml PeerIp"

return

fi

FilePath=$1

AttrName=" $2="

sed 's/>/>\n/g' $FilePath | sed 's/

}

文章评论

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值