Click here to Skip to main content
Click here to Skip to main content

Generate .cs class from XML

By , 16 Dec 2011
 

Introduction

Series Part 1) This sample generates C# classes from XML. It uses hard coded relations between XML format and class format such that, elements are classes and attributes are properties. Therefore, it won't work with XML formats where elements contain values. I will release another step in the series for that task. Also how to handle embedded classes and serializers. This is just the first step but actually even this can be quite useful if you do a lot of work in XML because generally that is how you want your XML formatted. I will also release some formatters that are compatible to come.

Refrences:

Utililzes tips/articles:

http://www.codeproject.com/KB/silverlight/Silverlight_Splitter.aspx

http://www.codeproject.com/Tips/300799/Iterate-XML-with-XMLReader

Using the code

XmlEntityToClassGenerator.ToClass("<Car name=\"Cayenne\"></Car>")

will generate:

public class Car

{

      public string Name {get;set;}

}

Refer to file XmlEntityToClassGenerator.cs. If you have a question I WILL append the article with the comments. Consider this a tip and trick with a downloadable sample please. Otherwise, if you want a book go buy one, I am not here to entertain you with a funny story and a segway into XML stuff followed by a dreary explaination parroting the code which is right there. I am however, very interested in helping anyone or talking about it. So, let the 1's / flames / comments fly !.

Thanks,

R.J.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

rj45
Software Developer (Senior)
Canada Canada
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 1memberrobert w. mcbean17 Dec '11 - 22:29 
attitude
QuestionHow is it different from XML Schema Definition Tool from Microsoft?memberharisundeep16 Dec '11 - 19:39 
Curious to know how this is different from the XML Schema Definition Tool from Microsoft.
http://msdn.microsoft.com/en-us/library/x6c1kb0s%28v=vs.71%29.aspx[^]

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130523.1 | Last Updated 16 Dec 2011
Article Copyright 2011 by rj45
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid