In XML and XML Schema, namespaces are frequently used to ensure the uniqueness of entity names across schema boundaries. By default, XBinder does not use the namespace information when generating names for types, elements, and attributes in the C or C++ code. This is done to provide shorter and more concise names, but it sometimes leads to collisions and ambiguous names in the code.
There are a number of methods that can be used to remove this ambiguity. These are described below.
Use of the -useNSPfx Command Line Switch
Specifying -useNSPfxon the command line when compiling a set of XSD specifications will cause namespace prefixes specified in the schema to be added to the generated C or C++ names. This will ensure that no naming collisions will occur (this is only true, of course, if the XSD specifications being compiled are valid in their use of namespaces). However, the generated C or C++ names will be longer as they will be of the form <prefix>_<localName>where prefixis the defined namespace prefix and localNameis the local name for the item.
One thing to be aware of when using -useNSPfxis that prefixes for a given namespace URI can change across schemas. For this reason, it is recommended that all schemas that make up a project be compiled at once to ensure that the same prefix is used for a given name. This can be done by either including all of the schema filenames to be compiled on the command line at once, or by using the -all switch to instruct the compiler to compile all included and/or imported schemas. The prefix that is used for a given name is the first one encountered during the compilation process. If you know that namespace prefix names are maintained in a consistent manner across schemas (i.e. the same prefix is always used to describe a given URI), then it is OK to compile the schemas individually with this option.
Use of the -typeCasing and -elemCasing Command Line SwitchesGlobal element and type names may be the same in a given schema. While this may be a questionable programming practice from a logical point of view, it is legal and it will cause problems in XBinder generated code because the generated names will clash. This can even be the case within the same namespace; therefore, use of the -useNSPfxoption cannot be used to solve this problem.
The -typeCasingand/or -elemCasingoptions provide a quick and easy way to fix these names in all compiled schemas. By setting one or the other (or both) to different case values (upper or lower), you can ensure that no name collisions of this sort will occur. The typical convention when using these switches is to set element name case to lower and type name case to upper.
Use of the <prefix> Configuration File SettingMore specific control of naming problems can be achieved by using the <prefix> configuration file setting. This allows individual entities within a schema specification to be targeted for name alteration. It is a good alternative when you only have a few name clashes and do not want to add the verbosity to all names introduced by the -useNSPfxswitch.
See the section on configuration file use for specifics on how to use a configuration file to customize the compilation process. Using <prefix> in a configuration file causes the specified prefix name to be prepended to the generated C or C++ name. This will make the name of the targeted item different in the generated code from another entity having the same name.