XSDCXX(1) | General Commands Manual | XSDCXX(1) |
xsdcxx - W3C XML Schema to C++ Compiler
xsdcxx command [ options ]
file [ file ...]
xsdcxx help [ command ]
xsdcxx version
xsdcxx generates vocabulary-specific, statically-typed C++ mapping from W3C XML Schema definitions. Particular mapping to produce is selected by a command. Each mapping has a number of mapping-specific options that should appear, if any, after the command. Input files should be W3C XML Schema definitions. The exact set of the generated files depends on the selected mapping and options.
for command-specific help.
Command-specific options, if any, should appear after the corresponding command.
The C++ standard affects various aspects of the generated code that are discussed in more detail in various mapping-specific documentation. Overall, when C++11 is selected, the generated code relies on the move semantics and uses std::unique_ptr instead of deprecated std::auto_ptr.
When the C++11 mode is selected, you normally don't need to perform any extra steps other than enable C++11 in your C++ compiler, if required. The XSDCXX compiler will automatically add the necessary macro defines to the generated header files that will switch the header-only XSDCXX runtime library (libxsd) to the C++11 mode. However, if you include any of the XSDCXX runtime headers directly in your application (normally you just include the generated headers), then you will need to define the XSD_CXX11 macro for your entire project.
For the wchar_t character type the only valid value is auto and the encoding is automatically selected between UTF-16 and UTF-32/UCS-4, depending on the wchar_t type size.
The schema file provided to the compiler need not exist and is only used to derive the name of the resulting header file. Use the --extern-xml-schema option to include this file in the generated files for other schemas.
--namespace-map http://example.com/foo/bar=foo::bar
Will map the http://example.com/foo/bar XML Schema namespace to the foo::bar C++ namespace.
All the regular expressions are pushed into a stack with the last specified expression considered first. The first match that succeeds is used. Regular expressions are applied to a string in the form
filename namespace
For example, if you have file hello.xsd with namespace http://example.com/hello and you run xsd on this file, then the string in question will be:
hello.xsd. http://example.com/hello
For the built-in XML Schema namespace the string is:
XMLSchema.xsd http://www.w3.org/2001/XMLSchema
The following three steps are performed for each regular expression until the match is found:
1. The expression is applied and if the result is empty the next expression is considered.
2. All / are replaced with ::.
3. The result is verified to be a valid C++ scope name (e.g., foo::bar). If this test succeeds, the result is used as a C++ namespace name.
As an example, the following expression maps XML Schema namespaces in the form http://example.com/foo/bar to C++ namespaces in the form foo::bar:
%.* http://example.com/(.+)%$1%
See also the REGEX AND SHELL QUOTING section below.
For example, if you had the following import element in your schema
<import namespace="..." schemaLocation="base.xsd"/>
and compiled this fragment with --include-prefix schemas/, then the include directive in the generated code would be:
#include "schemas/base.hxx"
All the regular expressions are pushed into a stack with the last specified expression considered first. The first match that succeeds is used.
As an example, the following expression transforms paths in the form schemas/foo/bar to paths in the form generated/foo/bar:
%schemas/(.+)%generated/$1%
See also the REGEX AND SHELL QUOTING section below.
Note also that automatic dependency generation is not supported in the file-per-type mode (--file-per-type). In this case, all the generated files are produced with a single compiler invocation and depend on all the schemas. As a result, it is easier to establish such a dependency manually, perhaps with the help of the --file-list* options.
The semantics of providing options in a file is equivalent to providing the same set of options in the same order on the command line at the point where the --options-file option is specified except that the shell escaping and quoting is not required. You can repeat this option to specify more than one options file.
All the regular expressions are pushed into a stack with the last specified expression considered first. The first match that succeeds is used. Regular expressions are applied to a string in the form
filename namespace xpath
For instance:
hello.xsd http://example.com/hello element
hello.xsd http://example.com/hello type/element
As an example, the following expression makes all the derived names start with capital letters. This could be useful when your naming convention requires type names to start with capital letters:
%.* .* (.+/)*(.+)%\u$2%
See also the REGEX AND SHELL QUOTING section below.
--location-map http://example.com/foo.xsd=foo.xsd
For example, the following expression maps URL locations in the form http://example.com/foo/bar.xsd to local files in the form bar.xsd:
%http://.+/(.+)%$1%
See also the REGEX AND SHELL QUOTING section below.
namespace type-name
For example, the following expression maps type foo that is defined in the http://example.com/bar namespace to file name bar-foo:
%http://example.com/(.+) (.+)%$1-$2%
See also the REGEX AND SHELL QUOTING section below.
For example, the following expression maps schema files in the foo/1.0.0/ subdirectory to the files in the foo/ subdirectory. As a result, the #include directive paths for such schemas will be in the foo/schema.hxx form and the generated C++ files will be placed into the foo/ subdirectory:
%.*/foo/1.0.0/(.+)%foo/$1%
See also the REGEX AND SHELL QUOTING section below.
The type argument is an XML Schema type name that can be optionally qualified with a namespace in the namespace#name form. Note also that you will need to specify this option when compiling every schema file that has other ordered types derived from this type.
The compiler can be instructed to use a particular naming convention in the generated code. A number of widely-used conventions can be selected using the --type-naming and --function-naming options. A custom naming convention can be achieved using the --type-regex, --accessor-regex, --one-accessor-regex, --opt-accessor-regex, --seq-accessor-regex, --modifier-regex, --one-modifier-regex, --opt-modifier-regex, --seq-modifier-regex, --parser-regex, --serializer-regex, --const-regex, --enumerator-regex, and --element-type-regex options.
The --type-naming option specifies the convention that should be used for naming C++ types. Possible values for this option are knr (default), ucc, and java. The knr value (stands for K&R) signifies the standard, lower-case naming convention with the underscore used as a word delimiter, for example: foo, foo_bar. The ucc (stands for upper-camel-case) and java values a synonyms for the same naming convention where the first letter of each word in the name is capitalized, for example: Foo, FooBar.
Similarly, the --function-naming option specifies the convention that should be used for naming C++ functions. Possible values for this option are knr (default), lcc, and java. The knr value (stands for K&R) signifies the standard, lower-case naming convention with the underscore used as a word delimiter, for example: foo(), foo_bar(). The lcc value (stands for lower-camel-case) signifies a naming convention where the first letter of each word except the first is capitalized, for example: foo(), fooBar(). The java naming convention is similar to the lower-camel-case one except that accessor functions are prefixed with get, modifier functions are prefixed with set, parsing functions are prefixed with parse, and serialization functions are prefixed with serialize, for example: getFoo(), setFooBar(), parseRoot(), serializeRoot().
Note that the naming conventions specified with the --type-naming and --function-naming options perform only limited transformations on the names that come from the schema in the form of type, attribute, and element names. In other words, to get consistent results, your schemas should follow a similar naming convention as the one you would like to have in the generated code. Alternatively, you can use the --*-regex options (discussed below) to perform further transformations on the names that come from the schema.
The --type-regex, --accessor-regex, --one-accessor-regex, --opt-accessor-regex, --seq-accessor-regex, --modifier-regex, --one-modifier-regex, --opt-modifier-regex, --seq-modifier-regex, --parser-regex, --serializer-regex, --const-regex, --enumerator-regex, and --element-type-regex options allow you to specify extra regular expressions for each name category in addition to the predefined set that is added depending on the --type-naming and --function-naming options. Expressions that are provided with the --*-regex options are evaluated prior to any predefined expressions. This allows you to selectively override some or all of the predefined transformations. When debugging your own expressions, it is often useful to see which expressions match which names. The --name-regex-trace option allows you to trace the process of applying regular expressions to names.
The value for the --*-regex options should be a perl-like regular expression in the form /pattern/replacement/. Any character can be used as a delimiter instead of /. Escaping of the delimiter character in pattern or replacement is not supported. All the regular expressions for each category are pushed into a category-specific stack with the last specified expression considered first. The first match that succeeds is used. For the --one-accessor-regex (accessors with cardinality one), --opt-accessor-regex (accessors with cardinality optional), and --seq-accessor-regex (accessors with cardinality sequence) categories the --accessor-regex expressions are used as a fallback. For the --one-modifier-regex, --opt-modifier-regex, and --seq-modifier-regex categories the --modifier-regex expressions are used as a fallback. For the --element-type-regex category the --type-regex expressions are used as a fallback.
The type name expressions (--type-regex) are evaluated on the name string that has the following format:
[namespace ]name[,name][,name][,name]
The element type name expressions (--element-type-regex), effective only when the --generate-element-type option is specified, are evaluated on the name string that has the following format:
namespace name
In the type name format the namespace part followed by a space is only present for global type names. For global types and elements defined in schemas without a target namespace, the namespace part is empty but the space is still present. In the type name format after the initial name component, up to three additional name components can be present, separated by commas. For example:
http://example.com/hello type
foo
foo,iterator
foo,const,iterator
The following set of predefined regular expressions is used to transform type names when the upper-camel-case naming convention is selected:
/(?:[^ ]* )?([^,]+)/\u$1/
/(?:[^ ]* )?([^,]+),([^,]+)/\u$1\u$2/
/(?:[^ ]* )?([^,]+),([^,]+),([^,]+)/\u$1\u$2\u$3/
/(?:[^ ]* )?([^,]+),([^,]+),([^,]+),([^,]+)/\u$1\u$2\u$3\u$4/
The accessor and modifier expressions (--*accessor-regex and --*modifier-regex) are evaluated on the name string that has the following format:
name[,name][,name]
After the initial name component, up to two additional name components can be present, separated by commas. For example:
foo
dom,document
foo,default,value
The following set of predefined regular expressions is used to transform accessor names when the java naming convention is selected:
/([^,]+)/get\u$1/
/([^,]+),([^,]+)/get\u$1\u$2/
/([^,]+),([^,]+),([^,]+)/get\u$1\u$2\u$3/
For the parser, serializer, and enumerator categories, the corresponding regular expressions are evaluated on local names of elements and on enumeration values, respectively. For example, the following predefined regular expression is used to transform parsing function names when the java naming convention is selected:
/(.+)/parse\u$1/
The const category is used to create C++ constant names for the element/wildcard/text content ids in ordered types.
See also the REGEX AND SHELL QUOTING section below.
Type map files are used in C++/Parser to define a mapping between XML Schema and C++ types. The compiler uses this information to determine the return types of post_* functions in parser skeletons corresponding to XML Schema types as well as argument types for callbacks corresponding to elements and attributes of these types.
The compiler has a set of predefined mapping rules that map built-in XML Schema types to suitable C++ types (discussed below) and all other types to void. By providing your own type maps you can override these predefined rules. The format of the type map file is presented below:
Both schema-namespace and schema-type are regex patterns while cxx-namespace, cxx-ret-type, and cxx-arg-type are regex pattern substitutions. All names can be optionally enclosed in " ", for example, to include white-spaces.
schema-namespace determines XML Schema namespace. Optional cxx-namespace is prefixed to every C++ type name in this namespace declaration. cxx-ret-type is a C++ type name that is used as a return type for the post_* functions. Optional cxx-arg-type is an argument type for callback functions corresponding to elements and attributes of this type. If cxx-arg-type is not specified, it defaults to cxx-ret-type if cxx-ret-type ends with * or & (that is, it is a pointer or a reference) and const cxx-ret-type& otherwise. file-name is a file name either in the " " or < > format and is added with the #include directive to the generated code.
The # character starts a comment that ends with a new line or end of file. To specify a name that contains # enclose it in " ". For example:
# Pass apples by value.
#
apple apple;
# Pass oranges as pointers.
#
orange orange_t*;
}
In the example above, for the http://www.example.com/xmlns/my#orange XML Schema type, the my::orange_t* C++ type will be used as both return and argument types.
Several namespace declarations can be specified in a single file. The namespace declaration can also be completely omitted to map types in a schema without a namespace. For instance:
namespace http://www.example.com/xmlns/my
{
orange "const orange_t*";
}
The compiler has a number of predefined mapping rules that can be presented as the following map files. The string-based XML Schema built-in types are mapped to either std::string or std::wstring depending on the character type selected with the --char-type option (char by default).
byte "signed char" "signed char";
unsignedByte "unsigned char" "unsigned char";
short short short;
unsignedShort "unsigned short" "unsigned short";
int int int;
unsignedInt "unsigned int" "unsigned int";
long "long long" "long long";
unsignedLong "unsigned long long" "unsigned long
long";
integer "long long" "long long";
negativeInteger "long long" "long long";
nonPositiveInteger "long long" "long long";
positiveInteger "unsigned long long" "unsigned long
long";
nonNegativeInteger "unsigned long long" "unsigned long
long";
float float float;
double double double;
decimal double double;
string std::string;
normalizedString std::string;
token std::string;
Name std::string;
NMTOKEN std::string;
NCName std::string;
ID std::string;
IDREF std::string;
language std::string;
anyURI std::string;
NMTOKENS xml_schema::string_sequence;
IDREFS xml_schema::string_sequence;
QName xml_schema::qname;
base64Binary std::auto_ptr<xml_schema::buffer>
std::auto_ptr<xml_schema::buffer>;
hexBinary std::auto_ptr<xml_schema::buffer>
std::auto_ptr<xml_schema::buffer>;
date xml_schema::date;
dateTime xml_schema::date_time;
duration xml_schema::duration;
gDay xml_schema::gday;
gMonth xml_schema::gmonth;
gMonthDay xml_schema::gmonth_day;
gYear xml_schema::gyear;
gYearMonth xml_schema::gyear_month;
time xml_schema::time;
}
The last predefined rule maps anything that wasn't mapped by previous rules to void:
When you provide your own type maps with the --type-map option, they are evaluated first. This allows you to selectively override predefined rules.
When entering a regular expression argument in the shell command line it is often necessary to use quoting (enclosing the argument in " " or ' ') in order to prevent the shell from interpreting certain characters, for example, spaces as argument separators and $ as variable expansions.
Unfortunately it is hard to achieve this in a manner that is portable across POSIX shells, such as those found on GNU/Linux and UNIX, and Windows shell. For example, if you use " " for quoting you will get a wrong result with POSIX shells if your expression contains $. The standard way of dealing with this on POSIX systems is to use ' ' instead. Unfortunately, Windows shell does not remove ' ' from arguments when they are passed to applications. As a result you may have to use ' ' for POSIX and " " for Windows ($ is not treated as a special character on Windows).
Alternatively, you can save regular expression options into a file, one option per line, and use this file with the --options-file option. With this approach you don't need to worry about shell quoting.
If the input file is not a valid W3C XML Schema definition, xsdcxx will issue diagnostic messages to STDERR and exit with non-zero exit code.
Send bug reports to the xsd-users@codesynthesis.com mailing list.
Copyright (c) 2005-2014 Code Synthesis Tools CC.
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, version 1.2; with no Invariant Sections, no Front-Cover Texts and no Back-Cover Texts. Copy of the license can be obtained from http://codesynthesis.com/licenses/fdl-1.2.txt
July 2014 | XSDCXX 4.0.0 |