HELP! How to edit/create multiple XML files at once

Discuss modding questions and implementation details.
Post Reply
User avatar
King of Worms
Posts: 4753
Joined: Mon Oct 17, 2016 11:18 pm
Location: Scourg Barrow (CZ)
Contact:

HELP! How to edit/create multiple XML files at once

Post by King of Worms »

This is standard text in the xml file I need to edit, example:

<?xml version="1.0"?>
<info>
<rect scale="8">
<x>300</x>
<y>295</y>
<width>370</width>
<height>540</height>
</rect>
</info>

Lets say its a XML file for a part of a clothing "238_9-0_Aquamarine"

Than there are 10 other dyes of this clothing
238_9-0_White
238_9-0_Grey
238_9-0_Yellow
etc....

1st question:

What I need to do is to change lets say <y>295</y> TO <y>275</y> in ALL selected files.
How to do it fast?

2nd question is:
how can I create lets say 1000 XML files called the same as the source PNG files? With this content lets say:

<?xml version="1.0"?>
<info>
<rect scale="8">
<x>100</x>
<y>100</y>
</rect>
</info>


Thank you!
Last edited by King of Worms on Mon Oct 19, 2020 7:15 pm, edited 1 time in total.

User avatar
TheLacus
Posts: 1305
Joined: Wed Sep 14, 2016 6:22 pm

Re: HELP! How to edit multiple XML files at once

Post by TheLacus »

You should be able to do it with any text editor that can open a folder instead of a single file at a time. Visual Studio Code is an example.

User avatar
King of Worms
Posts: 4753
Joined: Mon Oct 17, 2016 11:18 pm
Location: Scourg Barrow (CZ)
Contact:

Re: HELP! How to edit multiple XML files at once

Post by King of Worms »

Thank you, I will look into that direction. Ive edited in the 2nd question, its in bold, can u take a look please?
2nd question is:
how can I create lets say 1000 XML files called the same as the source PNG files? With this content lets say:

<?xml version="1.0"?>
<info>
<rect scale="8">
<x>100</x>
<y>100</y>
</rect>
</info>


Thank you!

User avatar
pango
Posts: 3359
Joined: Wed Jul 18, 2018 6:14 pm
Location: France
Contact:

Re: HELP! How to edit/create multiple XML files at once

Post by pango »

Under Unix I'd use a tool like xmlstarlet,

Code: Select all

ᐅ xmlstarlet ed -u info/rect/y -v 275 /tmp/test.xml 
<?xml version="1.0"?>
<info>
  <rect scale="8">
    <x>300</x>
    <y>275</y>
    <width>370</width>
    <height>540</height>
  </rect>
</info>
Then iterate over files to modify:

Code: Select all

ᐅ for file in /tmp/*.xml; do 
  mv "$file" "$file.old" && 
  xmlstarlet ed -u info/rect/y -v 275 "$file.old" > "$file"
done
That tool has been compiled for Windows, so it should be usable there too, with some adjustments
Mastodon: @pango@fosstodon.org
When a measure becomes a target, it ceases to be a good measure.
-- Charles Goodhart

User avatar
Ferital
Posts: 282
Joined: Thu Apr 05, 2018 8:01 am

Re: HELP! How to edit/create multiple XML files at once

Post by Ferital »

Under Windows, one of the best tool for this is the good old Notepad++, unsurpassed in many ways (fast, simple and efficient). I use several IDE for programming but when it comes to quickly open a file and find/replace something in a bunch of files, I always go back to Notepad++.

Install it, open it and go to "Search", "Find in Files..." (or Ctrl+Shift+F), you will find what you want there.

User avatar
King of Worms
Posts: 4753
Joined: Mon Oct 17, 2016 11:18 pm
Location: Scourg Barrow (CZ)
Contact:

Re: HELP! How to edit/create multiple XML files at once

Post by King of Worms »

Notepad++ sounds the best, thank you everyone 😊

User avatar
King of Worms
Posts: 4753
Joined: Mon Oct 17, 2016 11:18 pm
Location: Scourg Barrow (CZ)
Contact:

Re: HELP! How to edit/create multiple XML files at once

Post by King of Worms »

Ferital wrote: Tue Oct 20, 2020 8:08 am Under Windows, one of the best tool for this is the good old Notepad++, unsurpassed in many ways (fast, simple and efficient). I use several IDE for programming but when it comes to quickly open a file and find/replace something in a bunch of files, I always go back to Notepad++.

Install it, open it and go to "Search", "Find in Files..." (or Ctrl+Shift+F), you will find what you want there.
This prog (I used it before but only for basic notes) with the info you provided - instant success, thanks a lot!!!

Post Reply