XML Notepad++ 中某些标签的增量数字

XML Notepad++ 中某些标签的增量数字

我有一个包含以下数据的 XML 文件

<Shipment>
 <ShipmentReference>1453464536</ShipmentReference>
 <ShipmentCode>2020IE</ShipmentCode>
</Shipment>
<Shipment>
 <ShipmentReference>7896535784</ShipmentReference>
 <ShipmentCode>2020IE</ShipmentCode>
</Shipment>
<Shipment>
 <ShipmentReference>5674321985</ShipmentReference>
 <ShipmentCode>2020IE</ShipmentCode>
</Shipment>

我想知道是否可以只编辑具有增量数字值的标签,如下所示

<Shipment>
 <ShipmentReference>9999999001</ShipmentReference>
 <ShipmentCode>2020IE</ShipmentCode>
</Shipment>
<Shipment>
 <ShipmentReference>9999999002</ShipmentReference>
 <ShipmentCode>2020IE</ShipmentCode>
</Shipment>
<Shipment>
 <ShipmentReference>9999999003</ShipmentReference>
 <ShipmentCode>2020IE</ShipmentCode>
</Shipment>

我不确定我们是否可以使用列编辑器

感谢任何帮助

谢谢

答案1

我建议在这里使用脚本。安装 Notepad++Python 脚本插件并运行以下 Python 脚本:

# ------------------------------------
# https://community.notepad-plus-plus.org/topic/15318/replace-text-with-incremented-counter
# Thanks to Scott Sumner for portions of this code 
# ------------------------------------
count = 9999999000

def calculate(m):
    global count
    count += 1
    return '<ShipmentReference>' + str(count) + '</ShipmentReference>'

editor.rereplace('<ShipmentReference>([0-9]+)</ShipmentReference>', calculate);

在此处输入图片描述

相关内容