[xsd-users] different behavior by xsd 3.0 and 3.2

Boris Kolpackov boris at codesynthesis.com
Mon Oct 6 09:28:54 EDT 2008


Hi Jeffrey,

Jeffrey Yu <jeffrey.yu at panpacificinvestment.com> writes:

> The problem is with the attribute named "value_type" of YCInput. In the
> xsd file, the type is "string". It becomes "decimal" in TSInput.hxx.

What happened is that the duplicate name escaping algorithm has changed
since 3.0.0. Here is what happens in more detail: your have the following
two attributes in YCInput:

<xs:attribute name="value" type="xs:decimal" default="0" />
<xs:attribute name="value_type" type="xs:string" default="NOT_DEFINED" />

In XSD 3.0.0 they were translated into these declarations:

  // value
  // 
  typedef ::xml_schema::decimal value_type1;

  const value_type1&
  value () const;

  // value_type
  // 
  typedef ::xml_schema::string value_type_type;

  const value_type_type&
  value_type () const;

As you can see the typedef name for the 'value' attribute conflicted
with the name of the 'value_type' attribute and was escaped to 
value_type1. Now here is what's generated by XSD 3.2.0:

  // value
  //
  typedef ::xml_schema::decimal value_type;

  const value_type&
  value () const;
 
  // value_type
  // 
  typedef ::xml_schema::string value_type_type;

  const value_type_type&
  value_type1 () const;

As you can see, the algorithm has changed slightly and now the second
occurrence of value_type is escaped. This change was made to make the
outcome of type escaping more predictable. The original logic was
trying to be clever in some simple cases like the above but was not
very consistent in some more complicated situations.

The root of the problem here is that the type names and function
names use the same naming conventions. Since 3.1.0 you can select
naming conventions for types and functions from a list of predefined,
widely-used conventions (you can also fine-tune this to provide your
custom convention). We can for example switch to the "upper camel case"
type naming to resolve the above problem:

$ xsd cxx-tree --type-naming ucc TSInput.xsd

This will result in the following definitions:

  // value
  // 
  typedef ::xml_schema::Decimal ValueType;

  const ValueType&
  value () const;

  // value_type
  // 
  typedef ::xml_schema::String Value_typeType;

  const Value_typeType&
  value_type () const;

For more information on naming conventions see the NAMING CONVENTION
section in the XSD Compiler Command Line Manual:

http://www.codesynthesis.com/projects/xsd/documentation/xsd.xhtml

Boris




More information about the xsd-users mailing list