3. May 2013 08:39
.NET . C#
Xml serialization in .NET can be done in various ways.but the easiest one which I believe is using xsd.exe to create the corresponding model class file from the xml file.Follow the easy steps explained below you can have your serializer-Deserializer ready immediately.
1) Launch Visual studio command prompt
2) Run the command as xsd.exe D:\Book.xml /outputdir:D:\Test
Give your xml file path instead of D:\Book.xml .The xsd file will be created in the directory D:\Test , by this command.
3) Run command xsd.exe /c /l:CS D:\Book.xsd /outputdir:D:\Test
After successful execution of this command you will get your C# model class Book.cs.See the directory directory D:\Test for the Book.cs file.
4) This generated model data set class can be used for serializing and deserializing the xml data.
De-serialization Code Snippet
XmlSerializer xmlSerializer = new XmlSerializer(typeof(Book));
using (StreamReader reader = new StreamReader("Book.xml"))
Book book= (Book)xmlSerializer.Deserialize(reader);
Serialization Code Snippet
using (StreamWriter writer = new StreamWriter("Book.xml"))
Book book= null;
Tags : xsd.exe
, Deserialize XML
, Serialize XML
, convert xsd to xml
, generate xml from xsd
, xml to xsd converter
, xsd to xml
, generate xsd from xml
, xml to xsd
, convert xml to xsd
, xml to xsd conversion