Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate POCO objects from xml file

Tags:

c#

xml

linq

poco

I have an XML file which roughly describes a database schema I am inheriting

I want to generate POCO objects for this file to give me a head start with the business objects in my C# application.

Is this possible and how?

like image 862
AJM Avatar asked Feb 25 '11 14:02

AJM


2 Answers

You could (and should) define a xsd which describes your XML file. From this XSD you can generate classes using xsd.exe.

If you need more control over your code generation (e.g. you aren't happy with the output of xsd.exe, want to add attributes, make changes, ...) you can use System.Xml.Serialization.XmlSchemaImporter, System.Xml.Serialization.XmlCodeExporter and CodeDom to adjust the generated code.

like image 177
Steven Jeuris Avatar answered Oct 05 '22 23:10

Steven Jeuris


Yes,it can be done. Take a look at T4 text templetes http://www.hanselman.com/blog/T4TextTemplateTransformationToolkitCodeGenerationBestKeptVisualStudioSecret.aspx

like image 25
Stecya Avatar answered Oct 06 '22 01:10

Stecya