[xsd-users] Attribute named "type" generates post_xxx() skeleton code with invalid return data type

Boris Kolpackov boris at codesynthesis.com
Wed Feb 5 23:50:52 EST 2014


Hi Edward,

Edward Brabant <ebrabant at ramlabs.com> writes:

>  <xs:element name='domainfinder'>
>   <xs:complexType>
>    <xs:attribute name='type' use='required'>
>     <xs:simpleType>
> [...]
>     </xs:simpleType>
>    </xs:attribute>
> [...]
> 
> The corresponding entry in the XSD map file is:
> 
>      type std::string;
> 
> This causes XSD version 3.3.0 (on CentOS 6.3) to generate skeleton
> code with the signature:
>  
>     virtual void post_type ();
>  
> Note that if I change the attribute name to something other than
> "type", e.g. "types", the skeleton code is generated correctly,
> i.e. the return type is std::string.

The attribute's type is anonymous which XSD automatically morphs
to a named type. What most likely happens is you have another
anonymous type before it that got assigned the 'type' name.
And to avoid name clashes, the next 'type' types will be
named 'type1', 'type2', etc.

The tricky part is that there is no easy way to see what
names XSD assignes to anonymous types. Plus, even if you
could, that would not be very stable, since the names can
change when you change the schema.

So the best option here is to specify a custom regex for
anonymous types that includes both the element/attribute
name and the outer type name (so you will end up with 
'domainfinder_type'). This name should be stable and
should not conflict with any other names.

For more information on specifying such a regex, see the
--anonymous-regex option. With this method you can also see
the assigned names with the --anonymous-regex-trace option.

Boris



More information about the xsd-users mailing list