Click here to Skip to main content
Licence CPOL
First Posted 16 Dec 2011
Views 3,162
Downloads 110
Bookmarked 3 times

Generate .cs class from XML

By | 16 Dec 2011 | Article
Generate .cs class from XML

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



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. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 1 Pinmemberrobert w. mcbean22:29 17 Dec '11  
QuestionHow is it different from XML Schema Definition Tool from Microsoft? Pinmemberharisundeep19:39 16 Dec '11  

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

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