[xsd-users] Re: Resolving multiple inclusions of the same
elements/attributes/types
Boris Kolpackov
boris at codesynthesis.com
Mon Feb 13 09:53:15 EST 2012
Hi Lyndon,
Lyndon <mail.lyndon at gmail.com> writes:
> Is this something that's unique to the chameleon inclusion case?
I think just its name (chameleon) should suggest that something fishy
is going on here. This is one of many XML Schema "mis-features" where
the authors of the standard tried to be too clever for their own good
(they probably thought they are just giving the user more flexibility
and power). The result is that it doesn't map very well to other
programming languages. As I mentioned earlier, XSD maps normal
includes/imports to C++ #include directives. This mechanism has robust
ways (include guards) of dealing with multiple inclusions so everything
works well in that case.
With chameleon inclusion the included schema changes depending on
which namespace it is included into. As a result we cannot map it to
#include and the best the XSD compiler can do is to generated actual
types, etc., every time it sees a chameleon inclusion. This can
obviously lead to duplicate declaration in some cases.
So my suggestion is to avoid chameleon inclusion if you can.
> Would cxx-tree be able to resolve the problem if namespaces were
> defined in B.xsd and C.xsd or would I still suffer from the same
> duplicate definitions?
No, it should work fine, as discussed above.
> Sorry I also have a related question:
>
> Consider the chameleon inclusion case:
> 1) B.xsd, C.xsd D.xsd has no namespace defined.
> 2) B.xsd includes D.xsd
> 3) C.xsd includes D.xsd
> 4) A.xsd, which has namespace FOOBAR, includes B.xsd and C.xsd
>
> My compiler will give me the same "redefinition" errors for A.hxx because
> D.xsd is indirectly included twice into A.xsd. In this case, I don't have
> an easy out like in the previous scenario. Any suggestions or workarounds?
This should actually work fine, except that there was a bug that we have
fixed for the next release that affected this area. If you would like to
give it a try, let me know which platform you are using and I will build
you a pre-release binary.
Boris
More information about the xsd-users
mailing list