Generate POCO objects from xml file

隐身守侯 提交于 2019-12-20 12:34:04

问题


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?


回答1:


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.




回答2:


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




回答3:


Try SimpleXmlToCode .It does not require an XSD or anything. It generates good serializable code instantly.

Best of all, it's opensource.



来源:https://stackoverflow.com/questions/5118450/generate-poco-objects-from-xml-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!