這篇文章主要介紹“如何用shell生成簡單格式的xml”,在日常操作中,相信很多人在如何用shell生成簡單格式的xml問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”如何用shell生成簡單格式的xml”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!
以下是shell代碼:
create_xml.sh
代碼如下:
#! /bin/bash
#author: dengzhaoqun
#date: 201202/14
outfile=out
tabs=0
put(){
echo '<'${*}'>' >> $outfile
}
put_head(){
put '?'${1}'?'
}
out_tabs(){
tmp=0
tabsstr=""
while [ $tmp -lt $((tabs)) ]
do
tabsstr=${tabsstr}'\t'
tmp=$((tmp+1))
done
echo -e -n $tabsstr >> $outfile
}
tag_start(){
out_tabs
put $1
tabs=$((tabs+1))
}
tag_end(){
tabs=$((tabs-1))
out_tabs
put '/'${1}
}
tag_value(){
out_tabs
str=""
str=${1}' value="'${2}'"/'
put $str
}
以下是測試代碼:
ts_xml.sh
代碼如下:
#! /bin/bash
#author: dengzhaoqun
#date: 20120215
source './create_xml.sh'
put_head 'xml version='1.0' encoding="GBK"'
tag_start '投遞信息'
tag_start '硬件'
tag_value '網(wǎng)卡' 1
tag_end '硬件'
tag_end '投遞信息'
生成的xml文件如下
代碼如下:
<?xml version=1.0 encoding="GBK"?>
<投遞信息>
<硬件>
<網(wǎng)卡 value="1"/>
</硬件>
</投遞信息>
到此,關(guān)于“如何用shell生成簡單格式的xml”的學習就結(jié)束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續(xù)學習更多相關(guān)知識,請繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>
當前文章:如何用shell生成簡單格式的xml-創(chuàng)新互聯(lián)
本文路徑:http://chinadenli.net/article20/dhgcjo.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供搜索引擎優(yōu)化、用戶體驗、域名注冊、網(wǎng)站導航、云服務器、網(wǎng)頁設計公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容