Here's the shell code:
create_xml.sh
Copy Code code as follows:
#! /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))]
Todo
TABSSTR=${TABSSTR} ' \ t '
tmp=$ ((tmp+1))
Done
ECHO-E-N $tabsstr >> $outfile
}
Tag_start () {
Out_tabs
Put $
tabs=$ ((tabs+1))
}
Tag_end () {
tabs=$ ((tabs-1))
Out_tabs
Put '/' ${1}
}
Tag_value () {
Out_tabs
Str= ""
Str=${1} ' value= ' ' ${2} '/'
Put $str
}
Here is the test code:
ts_xml.sh
Copy Code code as follows:
#! /bin/bash
#author: Dengzhaoqun
#date: 20120215
SOURCE './create_xml.sh '
Put_head ' XML version= ' 1.0 ' encoding= ' GBK '
Tag_start ' Delivery information '
Tag_start ' Hardware '
Tag_value ' NIC ' 1
Tag_end ' Hardware '
Tag_end ' Delivery information '
The resulting XML file is as follows
Copy Code code as follows:
<?xml version=1.0 encoding= "GBK"?>
< delivery information >
< hardware >
< nic value= "1"/>
</Hardware >
</Delivery Information >