How to generate .NET 4.0 classes from xsd?
Solution 1:
simple enough; just run (at the vs command prompt)
xsd your.xsd /classes
(which will create your.cs
). Note, however, that most of the intrinsic options here haven't changed much since 2.0
For the options, use xsd /?
or see MSDN; for example /enableDataBinding
can be useful.
Solution 2:
xsd.exe as mentioned by Marc Gravell. The fastest way to get up and running IMO.
Or if you need more flexibility/options :
xsd2code VS add-in (Codeplex)
Solution 3:
I show you here the easiest way using Vs2017 and Vs2019 Open your xsd with Visual Studio and generate a sample xml file as in the url suggested.
- Once you opened your xsd in design view as below, click on xml schema explorer
2. Within “XML Schema Explorer” scroll all the way down to find the root/data node. Right click on root/data node and it will show “Generate Sample XML”. If it does not show, it means you are not on the data element node but you are on any of the data definition node.
- Copy your generated Xml into the clipboard
- Create a new empty class in your solution and delete the class definition. Only Namespace should remain
- While your mouse pointer focused inside your class, choose EDIT-> Paste Special-> Paste Xml as Classes