7.14. Generate a Class from a Schema

Problem

You need to create one or more VB .NET classes based on an XML schema. You can then create an XML document in the appropriate format using these objects and the XmlSerializer.

Solution

Use the xsd.exe command-line utility included with the .NET Framework. Specify the name of your schema file as a command-line argument, and add the /c parameter to indicate you want to generate class code.

How It Works

Recipe 7-13 introduced the xsd.exe command-line utility, which you can use to generate schemas based on class definitions. The reverse operation—generating VB .NET source code based on an XML schema document—is also possible. This is primarily useful if you want to write a certain format of XML document ...

Get Visual Basic 2008 Recipes: A Problem-Solution Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.