[AHK]解析xml文件,并将某属性值扩大
发布时间:2020-12-16 08:09:55 所属栏目:百科 来源:网络整理
导读:?xml version="1.0"?Rootrownum value="1" backupapplicationHP Data Protector/backupapplication policyAUTDR12_Daily/policy policytypeFileSystem/policytype dataretained31/dataretained fullbackup7/fullbackup backuptime0.17/backuptime retentionp
<?xml version="1.0"?> <Root> <rownum value="1"> <backupapplication>HP Data Protector</backupapplication> <policy>AUTDR12_Daily</policy> <policytype>FileSystem</policytype> <dataretained>31</dataretained> <fullbackup>7</fullbackup> <backuptime>0.17</backuptime> <retentionperiod>Short</retentionperiod> <peakmbps>11</peakmbps> <backupcategory>Fulls & Fulls</backupcategory> </rownum> <rownum value="2"> <backupapplication>HP Data Protector</backupapplication> <policy>AUTP_Appl_Monthly</policy> <policytype>FileSystem</policytype> <dataretained>268</dataretained> <fullbackup>91</fullbackup> <backuptime>2.31</backuptime> <retentionperiod>Long</retentionperiod> <peakmbps>12</peakmbps> <backupcategory>Fulls & Fulls</backupcategory> </rownum> </Root> 想把上面xml文件中的rownum值增加45,即1变成46、2变成47,但用正则表达式方式实现不了: I tried the following code: NeedleRegEx = <rownum value="(d+)"> Replacement = <rownum value="($1+45)"> Temp := RegExReplace(Temp,NeedleRegEx,Replacement) But this changes it into <rownum value="1+45"> while I want <rownum value="46"> AutoHotkey代码如下: doc := ComObjCreate("MSXML2.DOMDocument.6.0") if(!doc.loadXml(xmlString)) { msgbox % "Hey! That's no valid XML!" ExitApp } rownums := doc.getElementsByTagName("rownum") Loop % rownums.length { rownum := rownums.item(A_Index-1) value := rownum.getAttribute("value") value += 45 rownum.setAttribute("value",value) } doc.save("myNewFile.xml") 完美解决! (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |