Type map files are used to define a mapping between XML Schema
and C++ types. For C++/Parser, 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. For C++/Serializer, type maps are used to determine
the argument type of pre
functions in
serializer skeletons corresponding to XML Schema types as
well as return types for callbacks corresponding to elements
and attributes of these types.
The compiler has a set of predefined mapping rules that map
the built-in XML Schema types to suitable C++ types (discussed
in the following sub-sections) 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:
namespace <schema-namespace> [<cxx-namespace>] { (include <file-name>;)* ([type] <schema-type> <cxx-ret-type> [<cxx-arg-type>];)* }
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_*
function
in C++/Parser or for element/attribute callbacks in C++/Serializer.
Optional <cxx-arg-type>
is an argument type
for element/attribute callbacks in C++/Parser or for the
pre
function in C++/Serializer. 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:
namespace http://www.example.com/xmlns/my my { include "my.hxx"; # 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:
include "my.hxx"; apple apple; namespace http://www.example.com/xmlns/my { orange "const orange_t*"; }
The compiler has a number of predefined mapping rules
for the built-in XML Schema types that vary depending on
the mapping used. They are described in the following
subsections. The last predefined rule for all the mappings
maps anything that wasn't mapped by previous rules to
void
:
namespace .* { .* void 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.
The C++/Parser mapping provides a number of predefined type map rules for the built-in XML Schema types. They can be presented as the following map files:
namespace http://www.w3.org/2001/XMLSchema { boolean bool bool; 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; negativeInteger long long; nonPositiveInteger long long; positiveInteger "unsigned long" "unsigned long"; nonNegativeInteger "unsigned long" "unsigned long"; float float float; double double double; decimal double double; NMTOKENS xml_schema::string_sequence*; IDREFS xml_schema::string_sequence*; base64Binary xml_schema::buffer*; hexBinary 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; }
If the --no-stl
option is not specified,
the following mapping is used for the string-based XML Schema
built-in types:
namespace http://www.w3.org/2001/XMLSchema { include <string>; 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; QName xml_schema::qname; }
Otherwise, a C string-based mapping is used:
namespace http://www.w3.org/2001/XMLSchema { string char*; normalizedString char*; token char*; Name char*; NMTOKEN char*; NCName char*; ID char*; IDREF char*; language char*; anyURI char*; QName xml_schema::qname*; }
The C++/Serializer mapping provides a number of predefined type map rules for the built-in XML Schema types. They can be presented as the following map files:
namespace http://www.w3.org/2001/XMLSchema { boolean bool bool; 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; negativeInteger long long; nonPositiveInteger long long; positiveInteger "unsigned long" "unsigned long"; nonNegativeInteger "unsigned long" "unsigned long"; float float float; double double double; decimal double double; NMTOKENS "const xml_schema::string_sequence*"; IDREFS "const xml_schema::string_sequence*"; base64Binary "const xml_schema::buffer*"; hexBinary "const 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; }
If the --no-stl
option is not specified,
the following mapping is used for the string-based XML Schema
built-in types:
namespace http://www.w3.org/2001/XMLSchema { include <string>; 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; QName xml_schema::qname; }
Otherwise, a C string-based mapping is used:
namespace http://www.w3.org/2001/XMLSchema { string "const char*"; normalizedString "const char*"; token "const char*"; Name "const char*"; NMTOKEN "const char*"; NCName "const char*"; ID "const char*"; IDREF "const char*"; language "const char*"; anyURI "const char*"; QName "const xml_schema::qname*"; }
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,
xsde
will issue diagnostic messages to STDERR
and exit with non-zero exit code.
Send bug reports to the xsde-users@codesynthesis.com mailing list.