i have following class:
using system.collections; using system.xml; using system.xml.serialization; public class resource { [xmlattribute("name")] public string m_name { get; set; } public string[] itemdrop; }
and xml file:
<resourcedata> <resources> <resource name="iron ore"> <itemdrop type="array"> <value>iron piece</value> </itemdrop> </resource> <resource name="tree"> <itemdrop type="array"> <value>log</value> <value>leaves</value> <value>apple</value> </itemdrop> </resource> </resources> </resourcedata>
i'm trying deserialize file , place 2 resource objects in array.
it reads m_name there nothing in itemdrop array.
this how load data:
public static resourcecontainer load(string path) { var serializer = new xmlserializer(typeof(resourcecontainer)); using (var stream = new filestream(path, filemode.open)) { return serializer.deserialize(stream) resourcecontainer; } }
you surely need xmlarrayitem
attribute:
public class resource { [xmlattribute("name")] public string m_name { get; set; } [xmlarrayitem("value")] public string[] itemdrop; }
Comments
Post a Comment