Using the XSD Tool

Microsoft provides a tool with the .NET Framework SDK called XSD, the XML Schemas/DataTypes support utility. With this tool, you can generate schemas from source code, compiled assemblies, and XML documents, as well as generating source code in various .NET languages from schemas.

The XSD command-line syntax shown here is explained in Table 8-1:

xsd.exe filename.ext [argument [...]]
Table 8-1. XSD tool command-line syntax

Argument

Description

filename.ext

This argument specifies the name of the file to use as input. This can be either a CLR DLL (.dll) or executable file (.exe); an XML (.xml) file; or an XML Schema Definition (.xsd) or XML-Data-Reduced (.xdr) file. The type of the input file determines what other arguments are allowed.

/classes
/c

When an XSD file is specified, generates source code for classes as determined by the schema. This argument is mutually exclusive with /dataset.

/dataset
/d

When an XSD file is specified, generates source code for classes that are subclasses of System.Data.DataSet as determined by the schema. This argument is mutually exclusive with /classes.

/element:element
/e:element

When an XSD file is specified, this argument specifies which elements to generate types for. /element may be specified more than once. The default is to generate types for all elements.

/language:language
/l:language

When an XSD file is specified, this argument specifies the language to generate types in. language may be one of cs (C#), vb (Visual Basic.NET), or js (JScript). You may also specify the fully qualified name of any class that implements System.CodeDom.Compiler.CodeDomProvider. The default is cs.

/namespace:namespace
/n:namespace

When an XSD file is specified, this argument specifies the namespace to create types in. The default is Schemas.

/outputdir:outputdir
/o:outputdir

Specifies the directory in which to put output files. The default is the current directory. Generated schema files are named scheman.xsd, where n is a sequential number starting with 0. Generated source files are named with the schema filename and the appropriate extension for the language.

/uri:uri
/u:uri

When an XSD file is specified, this argument specifies the URI for the elements in the schema to generate code for.

/type:type
/t:type

When a DLL or EXE file is specified, this argument specifies what types to generate a schema for. If type is a fully qualified type name, the schema for that type is generated. If type is a type name without a namespace, schemas for all types with that name are generated. If type ends with a *, schemas are generated for all types with names starting with the name up to the *. /type may be specified more than once. The default is to generate schemas for all types.

/h
/?

Prints information on how to use XSD.

/nologo

Suppresses printing of the XSD copyright statement and version information banner.

As you can see from the command-line syntax, xsd can be used to generate either source code or an XML Schema, based on a variety of inputs. It’s a very useful tool for generating an XSD based on a .NET type or XML document you have already written, as well as generating source code for a .NET type based on an existing XSD.

Note

When an XML-Data-Reduced (XDR) document is specified on the command line, xsd generates an equivalent XSD document. XDR was introduced by Microsoft and the University of Edinburgh in 1998, based on the earlier XML-Data standard which formed the basis for much of XML Schema.

The most likely reason anyone would need to convert an XDR to an XSD is to support an application using Microsoft’s BizTalk Server. BizTalk Server is an application server supporting workflow and process management.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.5.68