XSD Sample

Sample Overview

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

Note: The 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 SSCLI implementation does not support Visual Basic .NET as a target language and does not support dataset functionality.  The following options that are available in the .NET Framework implementation of XSD are not supported in the SSCLI version.

Usage

clix xsd file.xdr [/outputdir:directory]
clix xsd file.xsd {/classes} [/element:element]
                      [/language:language] [/namespace:namespace]
                      [/outputdir:directory] [URI:uri]
clix xsd {file.dll | file.exe} [/outputdir:directory] [/type:typename [...]]
Argument Description
file.extension The input file to convert. You must specify the extension as one of the following: .xdr, .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 XML Schema Definition 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 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 UNIX system-based platforms, /? might 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.

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), or JS. You can also specify a fully qualified name for a class implementing System.CodeDom.Compiler.CodeDomProvider.
/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 XML Schema Definition 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 tool generates schemas for all types in the assembly.

Remarks

The XML Schema Definition 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 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

Sample Source and Build Output Locations

The sample source is found in sscli\samples\utilities\xsd. 

The source file is:

The build output location is %TARGETCOMPLUS%\samples\utilities\xsd.  The output file is an executable assembly named xsd.exe.

Building the Sample

All samples are built from the buildall script. 

You can also build all the samples by switching to the root of the sample directory, sscli\samples, and typing build -c.

You can build this specific sample by switching to the sample directory and typing build -c.

Running the Sample

These steps require that the Shared Source CLI (SSCLI) be already built and functional.

  1. Run env.bat or source the env.csh or env.sh script files, depending on your platform.
  2. Switch to the %TARGETCOMPLUS%\samples\utilities\xsd directory.
  3. Type the following command:

    clix xsd.exe xsdfile


Copyright (c) 2002 Microsoft Corporation. All rights reserved.