I was thinking about making a tool to improve my map with some events for a game I’m planning, so I added a short XML Element to the end of the file, but the next time I saved my map the extra XML code was lost. There should be something to save the extra data in the savefiles.
There is no way for Tiled to do this unless it would keep a copy of the entire XML file in memory and just do updates to it before saving it back. This is not a viable approach since the map may also be stored in JSON or any other format, which have or would need their own in-memory representation to preserve arbitrary data.
The only way to reliably include data in the TMX file is by adhering to the TMX format, and putting custom information into the custom properties that are made for doing this. When this mechanism does not suit your use-case, you will have to store your information in another file.
It would be pretty easy to save custom data within an object that you define, or even as a layer or map property. Another solution, and one I use for my game, is I store extra information in json files that are stored alongside the map. For instance, town.tmx would be next to town.json which contains the events for that map. I prefer to keep the tiled data and my other data somewhat separate because I never know for sure what is going to happen with the tiled data format and I want to be able to keep using it as it changes; and a lot of the type of data I am adding (conversation options, the weight differences of item types) is just easier to edit in a text file than it is in the map.