Alex Rivera | Logout

Generate POCO objects from xml file

Asked 2011-02-25T14:35:54.717
10

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?

Edit
Report

2 Answers

8

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.

answered 2011-02-25T15:03:16.377
4
answered 2011-02-25T14:40:59.083

Your Answer