从生成xml文件POCO对象 [英] Generate POCO objects from xml file
问题描述
我有一个粗略描述了数据库架构,我继承了一个XML文件
I have an XML file which roughly describes a database schema I am inheriting
我要生成POCO对象,这个文件给我一个头与创业对象在我的C#应用程序。
I want to generate POCO objects for this file to give me a head start with the business objects in my C# application.
这是可能的,怎么样?
推荐答案
您可以(也应该)定义了一个 XSD 描述XML文件。从这个XSD那么您可以使用 XSD.EXE 类。
You could (and should) define a xsd which describes your XML file. From this XSD you can generate classes using xsd.exe.
如果你需要在你的代码生成更多的控制(例如,你不快乐与XSD.EXE的输出,要添加属性,进行更改,... ),您可以使用 System.Xml.Serialization.XmlSchemaImporter,System.Xml.Serialization.XmlCodeExporter和的CodeDOM ,以调整生成的代码。
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.
这篇关于从生成xml文件POCO对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!