XSD/Schema compilation checklist

From Code Synthesis Wiki

Jump to: navigation, search

This page provides a checklist-like run through the most commonly used XSD command line options. For more details on each option as well as for the complete list of options refer to the XSD command line interface documentation (man pages).


Common Options

The following options are available for all mappings:

  • If you are using C++11, then it makes sense to enable this mode in the generated code by adding the --std c++11 option.
  • You can map any XML Schema namespace (including the no-namespace case and built-in XML Schema namespace) to a custom C++ namespace with the --namespace-map option, for example, --namespace-map http://www.example.com/xmlns/my=Example::My. To place the generated code for a schema without a target namespace into a C++ namespace, use the empty string as XML Schema namespace: --namespace-map =My. To map a set of namespaces at once, the --namespace-regex option can be used.
  • To place the generated code into a specific directory, use the --output-dir options, for example, --output-dir src.
  • If you have several schema files and some of them are not self-sufficient (that is, you get XML Schema errors when trying to compile them separately with XSD) or have cyclic dependencies that involve inheritance (that is, you get a C++ error when compiling the generated code with the message saying that the base type is undefined) then you will need to use the file-per-type compilation mode which is turned on with the --file-per-type option. For more information about the file-per-type mode see this blog post.

C++/Tree Mapping Options

The following options are specific to the C++/Tree mapping:

  • If your schema defines several global elements while only some of them can be used as document root elements, then use the --root-element option to reduce the amount of the generated code, for example, --root-element library.
  • If you are using Visual Studio 2005 (8.0) and rely on IntelliSense, then you may want to compile your schemas with the --generate-intellisense option. This option is not needed if you are using Visual Studio 2008 (9.0).
  • If your schema is large and the resulting C++ source file is too big for the C++ compiler to handle (for example, the C++ compiler runs out of memory), then you can use the --parts option to split this file into several files, for example, --parts 4. The file-per-type compilation mode discussed above can also be used to address this issue.

C++/Parser Mapping Options

The following options are specific to the C++/Parser mapping:

  • You can request and suppress generation of the validation code with the --generate-validation and --suppress-validation options, respectively. By default, the validation code is generated when a non-validating underlying XML parser is used (Expat) and suppressed otherwise (Xerces-C++). See Section 5.5, "XML Schema Validation" in the C++/Parser Mapping Getting Started Guide for details.
  • You can request the generation of sample parser implementations with the --generate-noop-impl (generates empty implementations) and --generate-print-impl (generates implementations that print the data stored in XML) options.
  • You can request the generation of a sample test driver with the --generate-test-driver option.
Personal tools