New Feature: XML serialization (alpha)
The idea is to have a different way to store data, we have:
1. The Sphere like ini-file format
2. JSON in a raw file.
3. ... and now XML!
Example:
var file = new XmlFile("test.xml");
file.write("my_object", { x: 45, y: 54, ended: false, map: { name: "test.rmp", start: { x: 50, y: 50 } }, arr: [0, 1, 2] });
file.close();
Output:
<?xml version="1.0"?>
<!--Generated by Sphere SFML XML Content Serializer v1.0-->
<my_object s_x="45" s_y="54" s_ended="False">
<o_map s_name="test.rmp">
<o_start s_x="50" s_y="50" />
</o_map>
<a_arr s_0="0" s_1="1" s_2="2" />
</my_object>
Notice o_ means object, a_ array, s_ string, n_ number, b_ boolean, and I don't store functions.
The ultimate goal is to make data serialization easier than using JSON. Compare the above with this:
var file = OpenRawFile();
var json = JSON.stringify({ x: 45, y: 54, ended: false, map: { name: "test.rmp", start: { x: 50, y: 50 } }, arr: [0, 1, 2] });
file.write(CreateByteArrayFromString(json));
file.flush();
file.close();
Which is not bad, but not easy to read for filesaving purposes. XML I think is a cleaner, more user friendly way (and the output is also human readable and therefore easier to spot issues in the saving).
The proposed API
var file = new XmlFile();
file.write(name, object);
var o = file.read(name);
file.close();
I wanted it to be simple to use and store any kind of object datatype.