-
list xml deserialization
Hi,
I made an xsd (xml scheme) and made a class from that using xsd.exe.
in the generated class I got an array:
public Items[];
but I need something that I will be able to add and remove element from it and have a variable size. ( I read the array documentation and it says that arrays *do* have variable size but I could not figure out how it is)
so I wanted to change the array to ArrayList but then I saw in the System.Xml.Serialization.Deserialize that ArrayList are not supported.
What then can I do so I can have a list in a class that I can serialize and deserialize?
thanks.
-
Generic lists help here. From what I can tell, you can't serialize/deserialize a generic list directly (confirmation anyone? the docs are a little um, sketchy) but i've had a class inheriting from a list that's serializable.
Code:
public Main(int args)
{
MyList newList = new MyList();
// do the textbook serialization/deserialization for a normal class stating the type as MyList
}
public class MyList : List<string>
{
public MyList() // constructor
{
}
public string this[int index]
{
// getters and setters
}
}
-
.NET makes a little too easy sometimes, yeah you can serialize lists.
Code:
[XmlRoot]
public class Root
{
[XmlArray]
[XmlArrayItem("V")]
public List<string> Values;
}
the above will make the following XML file:
Code:
<Root>
<Values>
<V></V>
<V></V>
</Values>
</Root>
-
OMG C# rules. serialization is such a pain in C++.
Thank you both.
I did not think/know about Lists.
It works great with it.