[xsd-users] Namespace Problem

Boris Kolpackov boris at codesynthesis.com
Mon Jun 8 09:54:39 EDT 2020


Mario Scaramuzzino <mscaramuzzino at gmail.com> writes:

> I am trying to generate code from a certain number of XSDs which include
> other base XSDs.
> 
> For example:
> File1.xsd includes base.xsd
> File2.xsd includes base.xsd
> FileN.xsd includes base.xsd
> 
> And I also need to use the file-per-type option.
> 
> For each File.xsd I have to use a proper namespaces and I do it using the
> --namespace-map, for example getting different namespaces:
> File1.xsd -> ns1
> FileN.xsd -> nsN
> 
> To avoid code repetition (the File.xsd are many and also the base.xsd are
> many files) I would like to generate the base code just one time with a
> proper namespace (ex. nsBase). Is there a way to generate File.xsd code
> with the option that the base code already exists with its own namespace?

I assume you are using "chameleon inclusion" where base.xsd does not
have a namespace and is included into FileN.xsd which do have namespaces.
In this case, per the XML Schema spec, all the base.xsd declarations take
on the namespace of FileN.xsd.

This does result in the generated code bloat and the only way to get
rid of it is to change base.xsd to have its own namespace (and import
it in FileN.xsd) Note, however, that this may not be semantically
equivalent to the original, for example if base.xsd has namespace-
qualified elements (and which is the reason why the XSD compiler
cannot do this for your automagically).

You can search the xsd-users archives for "chameleon" for more
information on this topic.



More information about the xsd-users mailing list