读书人

怎么用shell脚本修改XML文件

发布时间: 2012-07-28 12:25:13 作者: rapoo

如何用shell脚本修改XML文件
有一个xml文件,格式如下,需要用shell脚本做一些处理。

<beauties name="FanBingBing" sex="femal" age="18" >
<head>
<hair colour="black" />
</head>
<close>
<dress style="Vintage " />
<drees style="Sweet" />
</close>
</beauties>


<beauties name="jolie" sex="femal" age="18">
<head>
<hair colour="Yellow" />
</head>
</beauties>

要求,输入人名作为参数一,穿衣风格作为参数二。根据人名索引所在的block,插入穿衣风格字段。如果该字段存在,则直接插入项,如 beauties.sh FanBingBing fashion 那么结果为
<beauties name="FanBingBing" sex="femal" age="18" >
<head>
<hair colour="black" />
</head>
<close>
<dress style="Vintage " />
<drees style="Sweet" />
<dress style="fashione" />
</close>
</beauties>
如果该字段不存在,则需要创建<close>字段,如beauties.sh jolie sexy 那么结果为
<beauties name="jolie" sex="femal" age="18">
<head>
<hair colour="Yellow" />
</head>
<close>
<dress style="sexy" />
</close>
</beauties>

请大小哥们帮个忙,多谢各位了~

[解决办法]
一定要用shell解决么,用perl、python、ruby什么的不是很方便吗,对xml文件的操作还是用专门的工具安全一些~
[解决办法]
拿shell操作xml是有点别扭。
[解决办法]
无所谓了..

读书人网 >UNIXLINUX

热点推荐