Bulk Editing Values in XML Files
-
Hello!
I’ve got a bit of a niche situation that comes up annoyingly often for me when modding: I need to bulk edit values within an entry in an XML file.
So, say I have the entry <hitpoints>****.**</hitpoints>. Whatever the value of the asterisks is, regardless of the formatting (decimals or whatnot), needs to be modified by a multiplier and then repeated across all entries until the end of the document. As far as I’m aware I’ll need to use a python script, but I’ve very limited prior experience with python, so I don’t know what that would like or how to integrate it into Notepad++.
Any help would be appreciated!
-
@ashiruni said in Bulk Editing Values in XML Files:
needs to be modified by a multiplier
… As far as I’m aware I’ll need to use a python scriptCorrect. See the FAQ: Can I do a Mathematical Replacement. It gives examples of how to do simple math replacements in the PythonScript plugin (it shows addition, but I think you can figure out how to change it to multiplication; the FAQ also links to another FAQ to show you how to set up the PythonScript plugin and run an example script). The regex needed to catch something in the
<hitpoints>
tag as you showed would be<hitpoints>(\d+\.\d+)</hitpoints>
-
@ashiruni said in Bulk Editing Values in XML Files:
So, say I have the entry <hitpoints>****.**</hitpoints>. Whatever the value of the asterisks is, regardless of the formatting (decimals or whatnot), needs to be modified by a multiplier and then repeated across all entries until the end of the document.
If you can reliably identify the value to be multiplied using a regular expression, the Columns++ plugin can do this.
After installing the plugin, you would select Search… from the Columns++ menu, then fill in:
Find what :
<hitpoints>([\d.]+)</hitpoints>
Replace with :<hitpoints>(?=reg(1)*
n)</hitpoints>
Search Mode: Regular Expression(replacing n with the multiplier) and then click Replace All.
Detailed help for Search and Formulas is available. This plugin is not yet available through Plugins Admin, but you can use the Quick Installer at the first link if you have Notepad++ installed in the default location; otherwise, install as explained here.
-
This is exactly what I was hoping for. Python is well and good, but I haven’t dived into it for good reason. Thanks for letting me know this exists ^.^