[xsd-users] Attribute named "type" generates post_xxx()
skeleton code with invalid return data type
Edward Brabant
ebrabant at ramlabs.com
Thu Feb 6 15:13:15 EST 2014
After several unsuccessful tries using the --anonymous-regex option, I avoided the problem altogether by changing element definition in the XSD file so that the 'type' attribute is no longer an anonymous type. This required changing the 'type' attribute entry in the map file.
Original 'domainfinder' element and 'type' attribute definition in the XSD file:
<xs:element name='domainfinder'>
<xs:complexType>
<xs:attribute name='type' use='required'>
<xs:simpleType>
<xs:restriction base='xs:string'>
<xs:enumeration value='filesystem'/>
<xs:enumeration value='eventchannel'/>
<xs:enumeration value='application'/>
<xs:enumeration value='servicename'/>
<xs:enumeration value='servicetype'/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name='name' type='xs:string' use='optional'/>
</xs:complexType>
</xs:element>
Revised 'domainfinder' element and 'type' attribute definition in the XSD file:
<xs:simpleType name='domainfinder_elem_type_attr_datatype'>
<xs:restriction base='xs:string'>
<xs:enumeration value='filesystem'/>
<xs:enumeration value='eventchannel'/>
<xs:enumeration value='application'/>
<xs:enumeration value='servicename'/>
<xs:enumeration value='servicetype'/>
</xs:restriction>
</xs:simpleType>
<xs:element name='domainfinder'>
<xs:complexType>
<xs:attribute name='type' use='required' type='domainfinder_elem_type_attr_datatype'/>
<xs:attribute name='name' type='xs:string' use='optional'/>
</xs:complexType>
</xs:element>
Original 'type' attribute entry in the map file:
type "std::string";
Revised 'type' attribute entry in the map file:
type domainfinder_elem_type_attr_datatype "std::string";
Regards,
Ed Brabant
Contractor
JTRS Test Application (JTAP) team, JTRS Test and Evaluation Lab (JTEL),
Joint Tactical Networking Center (JTNC) Technical Directorate (TD),
Space and Naval Warfare (SPAWAR) Systems Command (SSC) Pacific
________________________________________
From: Boris Kolpackov [boris at codesynthesis.com]
Sent: Wednesday, February 05, 2014 8:50 PM
To: Edward Brabant
Cc: xsd-users at codesynthesis.com
Subject: Re: [xsd-users] Attribute named "type" generates post_xxx() skeleton code with invalid return data type
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