Creating C# Class from an XML file

by Brad 25. February 2008 09:16

If you've existing XML files that you need to manipulate in C# there is no need to write your own class by hand. Visual Studio ships with a little known tool XSD.exe which will do all the leg work for you.

Step 1 (from a command prompt):

This will create an XSD based on the XML file, which in step 2 will allow the tool to create the C# class(s)

XSD.exe [XML_FILE]

Step 2 (from a command prompt):

Call the tool again, this time providing the newly created .xsd file, along with /c (for classes, you could use /d for a dataset) and /n for your project's namespace

XSD.exe [XSD_FILE] /c /n:[PROJECT NAMESPACE]

Other parameters that might be useful are /o: (out) which specifies the output directory

Step 3:

Add the newly created .cs file to your project, and bingo, job done!

Tags:

C# | Microsoft Visual Studio

Powered by BlogEngine.NET 1.5.0.7
Theme by Interakting

Interakting

A full service digital agency offering online strategy, design and usability, systems integration and online marketing services that deliver real business benefits and ensure your online objectives are met.

Calendar

<<  July 2010  >>
MoTuWeThFrSaSu
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

View posts in large calendar