Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I convert an XSD file to C# Class

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 ); 
like image 639
Arun Rana Avatar asked Nov 04 '11 13:11

Arun Rana


People also ask

What program opens XSD files?

You can open XSD files in Pattern Maker Viewer 4, Cross Stitch Saga, or Cross Stitch Paradise.

What is the use of XSD file in C#?

XSD is a schema language; you use it to define the possible structure and contents of an XML format. A validating parser can then check whether an XML instance document conforms to an XSD schema or a set of schemas.


2 Answers

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 
like image 77
George Johnston Avatar answered Oct 05 '22 10:10

George Johnston


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> 
like image 39
rockyashkumar Avatar answered Oct 05 '22 11:10

rockyashkumar