How can i convert XSD file to C# Class

爱⌒轻易说出口 提交于 2019-11-30 10:59:29

问题


I have a file in XSD format. How can I convert it to a C# class ?

I need class reference in other web applications where I need to make post call as per below:

var res = client.Post<Customer>("/customers", c ); 

回答1:


Use the XML Schema Definition Tool xsd.exe found in your framework tools to convert your schema into a serializable class or dataset.

xsd file.xsd {/classes | /dataset} [/element:element]
         [/language:language] [/namespace:namespace]
         [/outputdir:directory] [URI:uri]

And in example, whereas the C# class will be generated in the same directory as the xsd tool:

xsd /c YourFile.xsd



回答2:


you can do like this...

  <xsd xmlns='http://microsoft.com/dotnet/tools/xsd/'>
<generateClasses language='CS' namespace='Namespace.subnamespace'>
    <schema>FirstSchema.xsd</schema>
    <schema>AnotherSchema.xsd</schema>
    <schema>LastSchema.xsd</schema>
</generateClasses>
</xsd>


来源:https://stackoverflow.com/questions/8009672/how-can-i-convert-xsd-file-to-c-sharp-class

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