Mitochondrion
Member
I'm having problem with this. It gives me error saying "There is an error in XML document (2, 2)." I can't see anything wrong with my XML document. What I'm trying to achieve is to covert all the <game> tags into object in C#.
XML
C#
C#
XML
Code:
<?xml version="1.0" encoding="utf-8" ?>
<games>
<game>
<name>...</name>
<year>...</year>
<platform>...</platform>
</game>
<game>
<name>...</name>
<year>...</year>
<platform>...</platform>
</game>
<game>
<name>...</name>
<year>...</year>
<platform>...</platform>
</game>
...
</games>
C#
Code:
public class game
{
public String name { get; set; }
public String year { get; set; }
public String platform { get; set; }
}
C#
Code:
XmlSerializer deserializer = new XmlSerializer(typeof(List<game>));
TextReader reader = new StreamReader("XML source file path...");
List<game> videogames = new List<game>();
videogames = (List<game>)deserializer.Deserialize(reader);
reader.Close();
MessageBox.Show("Name: " + videogame.name + "\nYear: " + videogame.year + "\nPlatform: " + videogame.platform);