[xsd-users] Multiple XML files with identical element names

Boris Kolpackov boris at codesynthesis.com
Wed Apr 30 03:37:09 EDT 2008


Hi Thomas,

Thomas Walter <thomas.walter at de.gm.com> writes:

> I want to parse multiple independent XML files using XSD. When I generate
> the object model of either XSD file I will later on get linker errors of
> duplicated objects. The issue is that the schemas use some same names for
> certain elements, e.g. each schema file includes a definition for revision
> log. This results in duplicated functions/objects. Is there a way to let
> the xsd compiler know to use a certain prefix for the generated code for
> one schema, a certain option?

The way to resolve this is to place the generated code into different C++
namespaces. For example, if you have a.xsd and b.xsd with identically-
named types then you can compile them like so:

xsd cxx-tree --namespace-map =foo a.xsd
xsd cxx-tree --namespace-map =bar b.xsd

This will result in the generated C++ code for a.xsd being placed into the
foo C++ namespace and for b.xsd -- into bar. If your schemas specify target
namespaces, then you will need to add that to the --namespace-map option,
for example:

xsd cxx-tree --namespace-map http://www.example.com/a=foo a.xsd

For more information on the --namespace-map option see the XSD Compiler
Command Line Manual:

http://codesynthesis.com/projects/xsd/documentation/xsd.xhtml

Boris




More information about the xsd-users mailing list