批处理删除指定文件如何实现修改XML指定内容并输出整个文档

批处理如何修改xml文件中指定位置/特征的字符串(更改指定节点/元素/标签里的文本) - BAT求助&讨论 -
批处理之家 批处理_BAT_CMD_DOS_VBS_Perl_Python_PowerShell - Powered by Discuz!
帖子96&积分110&技术0 &捐助0 &注册时间&
批处理如何修改xml文件中指定位置/特征的字符串(更改指定节点/元素/标签里的文本)
本帖最后由 pcl_test 于
07:42 编辑
我这有一个xml文件:integers.xml内容是:
&?xml version=&1.0& encoding=&utf-8&?&
&resources&
& & &integer name=&config_shortAnimTime&&200&/integer&
& & &integer name=&config_mediumAnimTime&&400&/integer&
& & &integer name=&config_longAnimTime&&500&/integer&& &
& & &integer name=&status_bar_notification_info_maxnum&&999&/integer&
& & &integer name=&preference_fragment_scrollbarStyle&&0x2000000&/integer&
& & &integer name=&kg_carousel_angle&&75&/integer&
& & &integer name=&kg_glowpad_rotation_offset&&0&/integer&
& & &integer name=&resumeboost_timeout_param&&300&/integer&
& & &/resources&
红色部分我要把数字缩小2倍,能否用批处理一次性修改。代码尽量高效而不要太复杂的。大大们帮忙看看。
未按版规发帖PB -4
帖子6203&积分18419&技术919 &捐助100 &注册时间&
使用第三方工具 gawk@gawk -F&&|&& &$2~/shortAnimTime|mediumAnimTime|longAnimTime|resumeboost_timeout_param/{$0=$1 \&^&\& $2 \&^&\& ($3/2) \&^&\& $4 \&^&\&};1& 旧.xml &新.xml复制代码
帖子96&积分110&技术0 &捐助0 &注册时间&
& & 我的系统是64位的。好像没有64位的gawk工具呀
帖子6203&积分18419&技术919 &捐助100 &注册时间&
& & 32 位的 gawk 就能胜任
帖子96&积分110&技术0 &捐助0 &注册时间&
& & 哦!谢谢!
帖子96&积分110&技术0 &捐助0 &注册时间&
& & 测试通过。感谢,向你学习。但是今天我不能评分了。不好意思
帖子96&积分110&技术0 &捐助0 &注册时间&
& & 如果我要把数字缩小3倍那怎么改?
帖子6203&积分18419&技术919 &捐助100 &注册时间&
& & 把 ($3/2) 这里的 2 改成你想要的数字
帖子96&积分110&技术0 &捐助0 &注册时间&
& & 好的,谢谢!
帖子512&积分1043&技术137 &捐助60 &注册时间&
Set FSO& &= CreateObject(&Scripting.FileSystemObject&)
Set File&&= FSO.OpenTextFile(&integers.xml&, 1, False)
Set File2 = FSO.OpenTextFile(&integers2.xml&, 2, True)
Set RegEx = New RegExp
& & RegEx.Pattern = &shortAnimTime|mediumAnimTime|longAnimTime|resumeboost_timeout_param&
& & RegEx.IgnoreCase = True
Set RegEx2 = New RegExp
& & RegEx2.Pattern = &[0-9]+&
& & RegEx2.IgnoreCase = True
While Not File.AtEndOfStream
& & Str = File.ReadLine
& & If RegEx.Test(Str) Then
& && &&&Set Matches = RegEx2.Execute(Str)
& && &&&For Each Match In Matches
& && && && &Num = Match / 2
& && &&&Next
& && &&&Str = RegEx2.Replace(Str, Num)
& & End If
& & File2.WriteLine Str
WEnd复制代码var FSO& &= new ActiveXObject('Scripting.FileSystemObject');
var File&&= FSO.OpenTextFile('integers.xml', 1);
var File2 = FSO.OpenTextFile(&integers2.xml&, 2, true);
while (!File.AtEndOfStream) {
& & str = File.ReadLine();
& & if (/shortAnimTime|mediumAnimTime|longAnimTime|resumeboost_timeout_param/.test(str)) {
& && &&&str = str.replace(/\d+/, function ($0){return $0 / 2});
& & }
& & File2.WriteLine(str);
}复制代码练手练手,话说VBS使用正则略复杂
[通过 QQ、MSN 分享给朋友]批处理bat怎么修改xml文件指定节点的值啊? - BAT求助&讨论 -
批处理之家 批处理_BAT_CMD_DOS_VBS_Perl_Python_PowerShell - Powered by Discuz!
帖子11&积分23&技术0 &捐助0 &注册时间&
批处理bat怎么修改xml文件指定节点的值啊?
&?xml version='1.0' encoding='utf-8'?&
&Server port=&9081& shutdown=&SHUTDOWN&&
&&&Service name=&Catalina&&
& & &Connector port=&& protocol=&HTTP/1.1&
& && && && && &connectionTimeout=&20000&
& && && && && &redirectPort=&8443& /&
& & &Connector port=&9088& protocol=&AJP/1.3& redirectPort=&8443& /&
& & &Engine name=&Catalina& defaultHost=&localhost&/&
&&&/Service&
我要修改 &Connector port=&& protocol=&HTTP/1.1&
& && && && && &connectionTimeout=&20000&
& && && && && &redirectPort=&8443& /&这里面port的值,要怎么操作啊。。。急求!!!!
帖子2865&积分7005&技术334 &捐助0 &注册时间&
你用记事本打开xml文件
看看是不是UTF-8编码
帖子11&积分23&技术0 &捐助0 &注册时间&
格式是ANSI的,有什么问题?
帖子11&积分23&技术0 &捐助0 &注册时间&
& & 格式是ANSI的,有什么问题?
帖子2865&积分7005&技术334 &捐助0 &注册时间&
sed -i &s#&Connector port=\&\& protocol=\&HTTP/1.1\&#&Connector port=\&1234\& protocol=\&HTTP/1.1\&#& server.xml复制代码
帖子11&积分23&技术0 &捐助0 &注册时间&
& & 必须借助第三方命令吗?下下来的sed是否放在bat同目录下即可?
帖子2865&积分7005&技术334 &捐助0 &注册时间&
& & 是的。试试就知道了。
帖子11&积分23&技术0 &捐助0 &注册时间&
& & 是整个压缩包都放到bat同目录下?还是需要解压?
帖子11&积分23&技术0 &捐助0 &注册时间&
& & 确实可以,,但是我想请教下,如果本来那个节点就有值,比如 port=&任意数值&,好像就改不了了呢?
帖子2865&积分7005&技术334 &捐助0 &注册时间&
hujunyu sed -i &s#&Connector port=\&.*\& protocol=\&HTTP/1.1\&#&Connector port=\&1234\& protocol=\&HTTP/1.1\&#& server.xml复制代码
帖子11&积分23&技术0 &捐助0 &注册时间&
多谢大神!!
帖子11&积分23&技术0 &捐助0 &注册时间&
& & &Resource name=&jdbc/aaa& auth=&Container&
& & & & & & & & type=&javax.sql.DataSource& username=&sa1& password=&sa1&
& & & & & & & & driverClassName=&net.sourceforge.jtds.jdbc.Driver&
& & & & & & & & url=&& maxActive=&200&
& & & & & & & & maxIdle=&200& maxWait=&10000& /&
我要给这里面的url赋值的话,应该肿么写啊,求大神再给一段。。谢谢。
帖子2865&积分7005&技术334 &捐助0 &注册时间&
hujunyu sed -i &s#url=\&.*\& maxActive=\&200\&#url=\&bbs.bathome.net\& maxActive=\&200\&#& server.xml复制代码
帖子11&积分23&技术0 &捐助0 &注册时间&
& & 哦。好像这个是根据每行来操作的!如果有两行一模一样的,就会两行都修改嘎!
帖子2865&积分7005&技术334 &捐助0 &注册时间&
& & 是的,sed命令就是这样工作的。
[通过 QQ、MSN 分享给朋友]}

我要回帖

更多关于 批处理删除指定后缀名 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信