Why use XML

Should I use XML in my games? I’m seeing in tutorials, classes being created from xml files (getting the attributes from the file) and I can’t see any advantages in using it.
Using XML to create classes don’t allow people modify them to change something in the game? What advantage it brings?
Thanks!!

You probably don’t mean creating classes from XML, but creating instances from XML.

If you have custom tools to create content for your game or if you want to be able to save a game you’ll need to export (serialize) it in a format that can be read to reconstruct (deserialize) the content/game state. XML is a popular choice for this because there’s good support for it in MG and it’s a very flexible format (but a bit verbose if you ask me).

1 Like

Yeah, it’s like @Jjagg said.

But, I guess that today JSON is our best choice for serialization, with JSON.NET, it’s an incredible lib and free4use.

And, I’m starting to use Lua instead, with NLua.
Creating C# instances in .lua files and returning then to the C#, IT’S AWESOME!
I suggest you to look and try some examples of NLua, you’ll love it.

I agree! I’ve used this lib before and liked it way better than the XML solution.

I’ve never taken the effort of learning Lua, but I’ve heard of NLua before, it’s a good lib for adding scripting to your game too apparently.

XML for me, has been just another way to load data… Only smarter.

I used to do it from txt files, but the built in structure of XML (the sort of syntax it has) makes it so much easier… You don’t have to know where the data you need is stored, you just ask for it by its variable name…

You can do things with the xml file, like run foreach loops on items it contains.
(foreach customer in catalogue, print shipping label)
Its just so much easier than txt…

I used XML to store terrain information that goes with terrain images, like terrain name, movement penalty, passability, or spritesheet coordinates , so I could add new terrain types without changing any code in my program…

Even the END USER can do this, no code required… Great for modding… And a nice power to have, for so small a price as to learn about XML… Its very simple once you’ve followed a tutorial or two… Which might take under an hour to complete…

1 Like

If your using it to save data like a level or something there are much better ways. The advantage of XML to me over other formats is really not a thing. It’s simple I guess? But for human readable files Json or Yaml or lua is really the way to go. For Json I would highly recommend servicestack.text if you don’t care about being able to read it I would highly recommend msgpack