這篇文章主要介紹“如何用shell生成簡(jiǎn)單格式的xml”,在日常操作中,相信很多人在如何用shell生成簡(jiǎn)單格式的xml問(wèn)題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”如何用shell生成簡(jiǎn)單格式的xml”的疑惑有所幫助!接下來(lái),請(qǐng)跟著小編一起來(lái)學(xué)習(xí)吧!
創(chuàng)新互聯(lián)建站是一家專注于網(wǎng)站建設(shè)、成都網(wǎng)站制作與策劃設(shè)計(jì),西和網(wǎng)站建設(shè)哪家好?創(chuàng)新互聯(lián)建站做網(wǎng)站,專注于網(wǎng)站建設(shè)十年,網(wǎng)設(shè)計(jì)領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:西和等地區(qū)。西和做網(wǎng)站價(jià)格咨詢:028-86922220以下是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
}
以下是測(cè)試代碼:
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生成簡(jiǎn)單格式的xml”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)?lái)更多實(shí)用的文章!
當(dāng)前文章:如何用shell生成簡(jiǎn)單格式的xml-創(chuàng)新互聯(lián)
本文路徑:http://muchs.cn/article20/dhgcjo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供搜索引擎優(yōu)化、用戶體驗(yàn)、域名注冊(cè)、網(wǎng)站導(dǎo)航、云服務(wù)器、網(wǎng)頁(yè)設(shè)計(jì)公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容