Numero incrementale per alcuni tag in XML Notepad ++

Oct 21 2020

Ho un file XML con i seguenti dati

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

Voglio sapere se è possibile modificare solo tag con valore numerico incrementale, qualcosa come di seguito

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

Non sono sicuro che possiamo usare l'editor delle colonne

Apprezzo qualsiasi aiuto

Grazie

Risposte

2 help-info.de Oct 21 2020 at 15:41

Consiglio di utilizzare uno script qui. Installa il plugin Notepad ++ Python Script ed esegui lo script Python di seguito:

# ------------------------------------
# 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);