how to convert your savegame file to xml, for easy viewing

The place to post your WML questions and answers.

Moderator: Forum Moderators

Forum rules
  • Please use [code] BBCode tags in your posts for embedding WML snippets.
  • To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
Post Reply
User avatar
iceiceice
Posts: 1056
Joined: August 23rd, 2013, 2:10 am

how to convert your savegame file to xml, for easy viewing

Post by iceiceice »

Recently I was doing something where I had to poke around in save game files. Doing this in a text editor can get annoying because they can get very long, a lot of information is repeated, some tags like [replay_save] repeat inside of themselves, so it's very easy to get confused where you are. (I also work on a netbook so I can't see as many lines at once.)

I decided it would be easier if I could view it as an xml file since then you can click on tags to collapse / expand them. Xml syntax is pretty similar to wml syntax so I wrote a shell script that does this, attached. This script will work most likely on any linux / mac / unix. To use it, unzip your save file, in same folder as script, then type e.g. "./wml2xml mysavegame > mysavegame.xml". (Make sure you used "chmod +x wml2xml" to give it permission to be executed.)

There are a ton of xml viewers out there, but also basically any modern web browser will render xml if you just drag an xml file into it. I found that chrome did a fine job. Edit: If you have access to the debian/ubuntu package "treeline" I find that this program is the best for this and is my tool of choice now.

Most likely you might be interested in this if you are trying to examine large replays to figure out why your add-on is not working, or trying to fix a broken replay. In principle you could also write something that goes back from xml to the save game file, so that you could use an xml editor to do the repairs, but it would require a lot more work and its probably not that helpful.

Hope someone finds this useful,
~iceiceice~

Edit: Even though the script is a mere 400 bytes, I am compressing it to circumvent forum attachment rules.

Technical details
Spoiler:
Attachments
wml2xml.gz
bash script to make savefile look like xml
(251 Bytes) Downloaded 311 times
Last edited by iceiceice on October 28th, 2013, 12:02 am, edited 4 times in total.
gfgtdf
Developer
Posts: 1432
Joined: February 10th, 2013, 2:25 pm

Re: how to convert your savegame file to xml, for easy viewi

Post by gfgtdf »

if i remember correcty there are also some wml editors out there wich support collapse / expand wml tags.

a toplevel is not just something your browser requires is is something that must be there according to the xml standart.

at third i realy think if you do something like this, a xml2wml would also be useful, for example if you want to fix a broken replay (i actualy think that is to much work even if they are in xml) you have to convert the xml back to the savegame format.

but thinking about this i realy wonder why the developers decided to use their own makrup language istead of using xml for wich there are already a thousand libraries.

EDIT: maybe the translatable strings are the reason.
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
User avatar
iceiceice
Posts: 1056
Joined: August 23rd, 2013, 2:10 am

Re: how to convert your savegame file to xml, for easy viewi

Post by iceiceice »

I will say it is not clear to me why the *savegames* are in wml rather than xml, iirc the translator program happens just after preprocessor, I don't think there are any translatable strings in save games files. Maybe they can hang around in lua somehow but I don't think I have ever seen a replay on the replay server with translatable strings in it.

Probably they already had an wml parser around so they just use it for everything ^_^
User avatar
Iris
Site Administrator
Posts: 6798
Joined: November 14th, 2006, 5:54 pm
Location: Chile
Contact:

Re: how to convert your savegame file to xml, for easy viewi

Post by Iris »

Saved games (of which replays are just a particular case) do contain translatable strings in their original _ "foo" form.
Author of the unofficial UtBS sequels Invasion from the Unknown and After the Storm.
User avatar
iceiceice
Posts: 1056
Joined: August 23rd, 2013, 2:10 am

Re: how to convert your savegame file to xml, for easy viewi

Post by iceiceice »

Hmm, it seems that some strings are left untranslated as you say and some appear in translated form. Anyways, yes, it definitely makes it harder to go to xml reverseably and simply.
JaMiT
Inactive Developer
Posts: 511
Joined: January 22nd, 2012, 12:38 am

Re: how to convert your savegame file to xml, for easy viewi

Post by JaMiT »

gfgtdf wrote:but thinking about this i realy wonder why the developers decided to use their own makrup language istead of using xml for wich there are already a thousand libraries.
Not sure if you noticed the tense conflict in this statement: "decided", past tense, as in over 10 years ago, versus "are", present tense. I rather doubt Dave had the ability to peer a decade into the future when making design decisions. A better statement would assess the number of good XML libraries from the time the decision was made.
amir
Posts: 25
Joined: August 24th, 2008, 10:43 am

Re: how to convert your savegame file to xml, for easy viewing

Post by amir »

I've written a tool that successfully converts wml files to xml. Internally it uses the wesnoth parser code. https://github.com/kallaballa/WML2XML
User avatar
josteph
Inactive Developer
Posts: 741
Joined: August 19th, 2017, 6:58 pm

Re: how to convert your savegame file to xml, for easy viewing

Post by josteph »

Thanks for sharing that, amir.

Another way:

Code: Select all

zcat ~/.local/share/wesnoth/1.14/saves/DiD-Saving_Parthyn_replay.gz > foo
/usr/share/games/wesnoth/1.14/data/tools/wesnoth/wmlparser3.py -j -i foo
That outputs json. It's possible to convert json to xml but I generally just deal with it as is.
Post Reply