yes. Using System.Xml.Serialization.XmlSerializer. Here is some sample code:
using System;
using System.IO;
using System.Xml.Serialization;
namespace Holmok.Utilities
{
public class serial
{
public static void ObjectToXml(object obj, string path_to_xml)
{
//serialize and persist it to it's file
try
{
XmlSerializer ser = new XmlSerializer(obj.GetType());
FileStream fs = File.Open(
path_to_xml,
FileMode.OpenOrCreate,
FileAccess.Write,
FileShare.ReadWrite);
ser.Serialize(fs,obj);
}
catch (Exception ex)
{
throw new Exception(
"Could Not Serialize object to " + path_to_xml,
ex);
}
}
}
}
srinanthuram
Contributor
6800 Points
1549 Posts
Re: is it possible to convert a xml to c# classes?
Feb 25, 2012 07:10 PM|LINK
hi
yes. Using System.Xml.Serialization.XmlSerializer. Here is some sample code:
using System; using System.IO; using System.Xml.Serialization; namespace Holmok.Utilities { public class serial { public static void ObjectToXml(object obj, string path_to_xml) { //serialize and persist it to it's file try { XmlSerializer ser = new XmlSerializer(obj.GetType()); FileStream fs = File.Open( path_to_xml, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite); ser.Serialize(fs,obj); } catch (Exception ex) { throw new Exception( "Could Not Serialize object to " + path_to_xml, ex); } } } }http://www.codeguru.com/forum/showthread.php?t=441772