Search Unity

Save to XML file clarification/help needed

Discussion in 'Scripting' started by Krodil, Mar 22, 2011.

  1. Krodil

    Krodil

    Joined:
    Jun 30, 2010
    Posts:
    141
    Hi,
    I have managed to use the script from unifycommunity in saving some positions and other variables into an xml file.
    After this has been done, my plan is to plot data through python, but my xml file ends up looking kind of strange.
    script reference:http://www.unifycommunity.com/wiki/index.php?title=Save_and_Load_from_XML

    Instead of having a 'nice' xml file I get some weird stuff with "<anyType xsi:type="xsd:double">497</anyType>"
    I therefore have issues in reading the file properly.
    My xml file is attached as a *rar:

    The script I use is also attached:

    Any clever minds?
     

    Attached Files:

    • $test.rar
      File size:
      404 bytes
      Views:
      409
    • $XML.js
      File size:
      6.4 KB
      Views:
      775
  2. Antitheory

    Antitheory

    Joined:
    Nov 14, 2010
    Posts:
    549
    You need to use XML serialization attributes... I don't recall how to use attributes in UnityScript... but in C#:

    [Serializable]
    [XmlRoot("SomeClass")]
    public class SomeClass{

    [XmlAttribute]
    public float attrib1;
    [XmlAttribute]
    public float attrib2;
    [XmlAttribute("alternate-name")]
    public string attrib3;

    [XmlElement("item")]
    public float[] items;

    }

    would spit out this xml when serialized (I just assumed you put some values in...)

    <?xml version="1.0" encoding="utf-8" ?>
    <SomeClass attrib1= "100.1" attrib2 = "200.2" alternate-name="some string">
    <item>23.132</item>
    <item>123.341</item>
    <item>231.21</item>
    </someClass>

    There other serialization attributes you can use to further customize the serialization process.. The MSDN docs will explain it well enough
     
  3. Krodil

    Krodil

    Joined:
    Jun 30, 2010
    Posts:
    141