When to use XML?

So I’ve recently been wondering. When is the correct time to use an XML file to store data? I’m a little “confused” as to when it’s judicious to employ an XML file and when it’s best to use system collections or other variables to store data.

For example lets say I have a turn based strategy game. Is it best to store the base stats or units inside an XML file and then load them into “character sheet” scripts modifying the base stats as needed as they are loaded into the script? When is it generally considered best practice to start using XML. Is there a tutorial or other article about using XML with Unity that might want to look at?

You are correct. You should use XML to setup stats. This way you can change the stats without having to recompile. And anyone can edit it without having access to your code.

It’s not an either/or thing…you still need system collections and variables; XML is just a format for storing them. If you have Civilization IV, look at that for an example (in the Assets/XML folder), where units info, tech info, etc. are stored in XML files. It’s usually not really a good idea to use it for, say, maps, which would generally be better off using a custom binary format because of the amount of data. (Although Civ IV does use an XML-ish format for maps, which makes the file sizes ridiculously bloated.)

–Eric

Perhaps I was not entirely clear. My thought was that I should store “base” values inside an XML document. Then I can parse them into scalars, or collections inside a kind of “stats” script stored on the gameObject.

Does UnityScript have an XMLReader? Does C# have an XMLReader? Where should I look to start educating myself?

http://stackoverflow.com/questions/55828/best-practices-to-parse-xml-files

–Eric

I don’t know what I would do without you (probably circle about in endless confusion)! Thanks so much!

Generally the answer is: If a non-Unity system needs to access the data then a format such as XML would make sense. Otherwise working in prefabs, custom assets and asset bundles gives you more speed and out-of-the-box integration.