[AHK]解析xml文件,并将某属性值扩大

前端之家收集整理的这篇文章主要介绍了[AHK]解析xml文件,并将某属性值扩大前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。


<?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")


完美解决

原文链接:https://www.f2er.com/xml/293729.html

猜你在找的XML相关文章