Charu
Charu

Reputation: 2749

Huge XML to Model in C#

I am working with a huge XML using a tool in VS2010 able to convert it into a Model (.cs class). Now in order to read that XML, I am parsing through the tags and filling in my objects in the Model. Just want to know if I am on the right track or there's a easier way to now load the Model with xml data

Upvotes: 0

Views: 72

Answers (1)

ywm
ywm

Reputation: 1127

You can use the XmlSerializer class to do this for you.

using(StreamReader reader = File.OpenText("FilePath"))
{
   XmlSerializer serial = new XmlSerializer(typeof(MyModel));
   MyModel model = serial.Deserialize(reader);
}

Upvotes: 2

Related Questions