-1

I am looking to add elements to my XML document. A single element should be duplicated, while also incrementing its value - by using Notepad++.

Example XML

Like below the <rateCode> element was duplicated incrementing values by 1:

<rateCode>1</rateCode>
<rateCode>2</rateCode>
<rateCode>3</rateCode>

and so on till 1000.

Is there any way to achieve this in Notepad++ ?

hc_dev
  • 8,389
  • 1
  • 26
  • 38
tulu matinee
  • 61
  • 1
  • 9

2 Answers2

1

Alternative:

Use a number generator and copy-paste ( https://numbergenerator.org/numberlist/1-1000 )

In Notepad++, use 'Search | Replace` regex:

Find what: ^(\d+)$ Replace with: <rateCode>\1</rateCode> Replace All

  • That's a KISS (keep it simple stupid) approach. Would prefer this to generate simple files from scratch. It basically generates a number of specified rows, which are then enhanced with static content - where simple must apply to the static content (the regex-replacement). – hc_dev Aug 17 '21 at 07:31
0

You could use a macro in Notepad++ to achieve this autofilling.

Or you can also use the Python Script plugin like described here: How to write macro for Notepad++?

# append a new XML element with incremented value
for i in range(1, 1000):
     editor.appendText("<rateCode>{}</rateCode>\r\n".format(i));

When new to Python programming get a brief introduction to implementing loops in Python, e.g. For Loop

hc_dev
  • 8,389
  • 1
  • 26
  • 38