[xsd-users] Problem with extension of complexType with simpleContent with required attribute

Boris Kolpackov boris at codesynthesis.com
Mon Jun 16 12:20:25 EDT 2008


Hi Ray,

Ray Lischner <rlischner at proteus-technologies.com> writes:

> The fix works too well. Suppose type A extends B, which extends 
> xsd:string. We have customized B so that the implementation
> actually derives from fundamental_base<unsigned>. (Specifically,
> we call B CUnsigned. It lets us write C-style hex numbers in the
> XML document, while using unsigned integers in the code. These
> particular elements are bit masks and are easier to express in
> hexadecimal.

Hm, interesting technique. I gave it some thought and it seems that
the proper way to support this kind of usage (that is, construction
of derived types by using implicit conversion c-tors provided by
customization of the base) would be to have an option to instruct
XSD to generate an extra c-tor which uses an instance of an 
intermediate base (the first simple type in the hierarchy).

I am, however, wondering if this has too limited an application since
the only way to achieve the same behavior for complex types or for
c-tors with two or more arguments would be to customize all derived
types and add the extra c-tors manually. In any case, I can add this
option to the 3.x.x code base if there is a real application that
needs it.

A workaround that should work in 2.3.1 would be to use union instead
of derivation. In other words, your type B would look like so:

<simpleType name="B">
  <union memberTypes="string"/>
</simpleType>

Since union is not explicitly derived from any type, the generated
code will use B as the ultimate base in any inheritance hierarchy.

Boris




More information about the xsd-users mailing list