XML Schema Definition Sample Tool (xsd.exe)

The XML Schema Definition sample tool generates XML schema or managed classes from XDR, XML, and XSD files, or from classes in an assembly.

Note: the Microsoft® Shared Source CLI (SSCLI) implementation does not include support for System.Data.* classes.  The ®Microsoft Visual Basic® .NET compiler is also not supported on the SSCLI.

The xsd sample tool is a managed application.  In order to execute managed applications you must use the clix application launcher.

clix xsd file.xdr [/outputdir:directory]
clix xsd file.xml [/outputdir:directory]
clix xsd file.xsd {/classes | /dataset} [/element:element]
             [/language:language] [/namespace:namespace]
             [/outputdir:directory] [URI:uri]
clix xsd {file.dll | file.exe} [/outputdir:directory] [/type:typename [...]]

The SSCLI implementation does not support Visual Basic .NET as a target language and does not support dataset functionality.  Some options below will not be supported on the SSCLI.

Argument Description
file.extension The input file to convert. You must specify the extension as one of the following: .xdr, .xml, .xsd, .dll, or .exe.

If you specify an XML schema file (.xsd extension), the xsd sample tool generates source code for runtime objects that correspond to the XML schema.

If you specify a runtime assembly file (.exe or .dll extension), the xsd sample tool generates schemas for one or more types in that assembly. You can use the /type option to specify the types for which to generate schemas. The output schemas are named schema0.xsd, schema1.xsd, and so on.  The xsd sample tool produces multiple schemas only if the given types specify a namespace using the XMLRoot custom attribute.

General Options

Options can be specified using either a dash (-) or a slash (/).

Option Description
/h[elp] Displays command syntax and options for the tool.
/o[utputdir]:directory Specifies the directory for output files. This argument can appear only once. The default is the current directory.
/? Displays command syntax and options for the tool.

When using this tool on the FreeBSD operating system /? may expand to a filename. Instead use the /help option variation, use -?, or enclose the /? option in quotes: "/?"

XSD File Options

You must specify only one of the following options for .xsd files.

Option Description
/c[lasses] Generates classes that correspond to the specified schema. To read XML data into the object, use the System.XML.Serialization.XMLSerializer.Deserializer method.
/d[ataset] Generates a class derived from DataSet that corresponds to the specified schema. To read XML data into the derived class, use the System.Data.DataSet.ReadXml method.

[SSCLIChange: This option is not supported on the SSCLI.]

You can also specify any of the following options for .xsd files.

Option Description
/e[lement]:element Specifies the element in the schema to generate code for. By default all elements are typed. You can specify this argument more than once.
/l[anguage]:language Specifies the programming language to use. Choose from CS (default), VB, or JS. You can also specify a fully qualified name for a class implementing System.CodeDom.Compiler.CodeDomProvider

[SSCLIChange: The VB language is not supported on the SSCLI.]

/n[amespace]:namespace Specifies the runtime namespace for the generated types. The default namespace is Schemas.
/u[ri]:uri Specifies the URI for the elements in the schema to generate code for. This URI, if present, applies to all elements specified with the /element option.

Assembly File Options

Option Description
/t[ype]:typename Specifies the name of the type to create a schema for. You can specify multiple type arguments. If typename does not specify a namespace, the xsd sample tool matches all types in the assembly with the specified type. If typename specifies a namespace, only that type is matched. If typename ends with an asterisk character (*), the tool matches all types that start with the string preceding the *. If you omit the /type option, the xsd sample tool generates schemas for all types in the assembly.

Remarks

The xsd sample tool performs the following operations:

XSD to Classes
Generates runtime classes from an XSD schema file. The generated classes can be used in conjunction with System.XML.Serialization.XMLSerializer to read and write XML code that follows the schema.
Classes to XSD
Generates an XML schema from a type or types in a runtime assembly file. The generated schema defines the XML format used by System.XML.Serialization.XMLSerializer.

The xsd sample tool only allows you to manipulate XML schemas that follow the XML Schema Definition (XSD) language proposed by the World Wide Web Consortium (W3C). For more information on the XML Schema Definition proposal or the XML standard, see http://w3c.org.

Example

The following command generates XML schemas for all types in the assembly myAssembly.dll and saves them as schema0.xsd in the current directory.

xsd myAssembly.dll  

Copyright (c) 2002 Microsoft Corporation