The following is the shell code:
Create_xml.sh
#! /Bin/bash # Author: dengzhaoqun # Date: 201202/14 OUTFILE = outtabs = 0put () {echo '<' $ {*} '> $ OUTFILE} put_head () {put '? '$ {1 }'? '} Out_tabs () {TMP = 0 tabsstr = "" While [$ TMP-lt $ (tabs)] dotabsstr =$ {tabsstr} '\ t' TMP =$ (TMP + 1) doneecho-e-n $ tabsstr >>>$ OUTFILE} tag_start () {out_tabsput $1 tabs =$ (tabs + 1)} tag_end () {tabs =$ (tabs-1 )) out_tabsput '/' $ {1} tag_value () {out_tabsstr = "" str =$ {1} 'value = "' $ {2} '"/'put $ STR}
The following is the test code:
Ts_xml.sh
#! /Bin/bash # Author: dengzhaoqun # Date: 20120215 source '. /create_xml.sh 'put _ head' XML version = '1. 0 'encoding= "GBK" 'tag _ start' shipping information' tag _ start' hardware 'tag _ value' network card '1tag_end' hardware 'tag _ end' shipping information'
The generated XML file is as follows:
<? XML version = 1.0 encoding = "GBK"?> <Shipping information>