.NET Class creation from XML schema = XSD.exe

While designing data exchange through the use of web services, one must think of what data is required to travel and how it can be described.

SOAP is an XML based format, so the most natural thing to happen is for us to design a schema for an XML representation of the information and later embed it on a SOAP envelope response.

When implementing a web service using .NET we can rest assured that the framework will provide the WSDL descriptor file automatically. But there’s another task to be done: implement the classes to support the data handling.

The good news is that .NET also has a tool for that matter, called XSD.EXE. It’s a command line utility that takes an XML schema file (XSD) and generates a file with the classes to serialize all the information described on the file.

.NET Command Line Prompt

.NET Command Line Prompt

To view the options available type: xsd.exe /?

XSD Command Options

XSD Command Options

To generate classes using C# for a schema called myData.xsd, with the dot.coder.data name space, you could type:

 xsd -c -l:c# -n:dot.coder.data myData.xsd

After the source code file is generated you can add it to your Visual Studio Project, for Web Services or other purposes.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s