[xsd-users] Syntax supported

Boris Kolpackov boris at codesynthesis.com
Thu Sep 22 09:01:15 EDT 2005


Vandi,

Vandi Verma <vandi at email.arc.nasa.gov> writes:

> I took your suggestion and reordered my groups and also removed unions.
> I'm not certain if the fact that xsd now does not return is related or
> not. I'm attaching my test schema in case there is another known problem
> you can detect by looking at it.

That's quite a schema you've got here ;-). It has a very deeply nested
hierarchy of anonymous types (i.e., type that are embedded inside
xsd:element definitions). By default xsd doesn't "flatten" such hierarchy.
Instead it generates hierarchy of anonymous types as hierarchy of nested
classes. Sometimes this leads to two or more (nested) classes for the
same type to be generated. In your case, however, because of such a
deep nesting, it resulted in hundreds of duplicate classes being generated.

As an experiment, I stripped your schema a bit and the resulting .hxx file
was 52M. I haven't seen anything like this before ;-).

I guess the best way to go here is to morph anonymous types into named
ones. In version 1.3.0 I only enabled such morphing for C++/Parser
mapping but for 1.4.0 it will be available for C++/Tree as well. So here
is what I did:

$ xsd cxx-tree --morph-anonymous vandi_test.xsd
vandi_test.xsd:23:39: error: element 'Node/EndCondition' is of type 'anyType'
vandi_test.xsd:23:39: info: 'anyType' is not supported
vandi_test.xsd:23:39: info: did you forget to specify 'type' attribute?

So I changed

<xsd:element name="EndCondition"/>

to read

<xsd:element name="EndCondition" type="Condition"/>

$ xsd cxx-tree --morph-anonymous vandi_test.xsd

Which compiled ok. It took about 6 seconds with non-optimized binary
of xsd on my Opteron 244 box. I plan to do some more optimizations that
should further reduce this time.

When I try to compile this I get:

$ g++ -I ~/work/xsd/xsd/libxsd -c vandi_test.cxx
In file included from vandi_test.cxx:40:
vandi_test.hxx:1806: error: redefinition of `struct ADD::_xsd_ADD'
vandi_test.hxx:1796: error: previous definition of `struct ADD::_xsd_ADD'
vandi_test.hxx:2106: error: invalid use of member `ADD::ADD'
vandi_test.hxx:2106: error: syntax error before `const'
vandi_test.hxx:1816: error: duplicate nested type `struct ADD::ADD'
vandi_test.hxx:1823: error: field `xsd::cxx::tree::sequence<ADD> ADD::ADD' with
   same name as class
vandi_test.hxx:2107: confused by earlier errors, bailing out


It appears that in ADD, SUB, MUL, and DIV there are members that
conflict with the class name. In other words it looks like this:

class ADD
{
  vector<NumericExpression>&
  ADD ();

  ...
};

Ideally, xsd should take care of this but it is a bit trickier than it
may seem so it doesn't do it yet.

There are two ways we can fix this. The most natural way is to change the
schema and add an explicitly-named types for ADD, SUB, MUL, and DIV, e.g.,
instead of

<xsd:element name="ADD">
  <xsd:complexType>
    <xsd:sequence>
      <xsd:group ref="NumericExpression" minOccurs="2" maxOccurs="2"/>
    </xsd:sequence>
  </xsd:complexType>
</xsd:element>

write

<xsd:complexType name="Add">
  <xsd:sequence>
    <xsd:group ref="NumericExpression" minOccurs="2" maxOccurs="2"/>
  </xsd:sequence>
</xsd:complexType>

<xsd:element name="ADD" type="Add"/>

The other way is to use --anonymous-regex option which allows you to
choose the name for an anonymous type (by default it is the same as
the element/attribute name). So we can do:

$xsd cxx-tree --morph-anonymous --anonymous-regex '%.* .* NumericExpression/(.)(..)$%$1\L$2\E%' vandi_test.xsd

This will result in the names being Add, Sub, Mul, and Div.

Or you may want to add prefix/suffix to all anonymous types (in order not
to confuse them with function names, for example). Then you could write:

--anonymous-regex '%.* .* (.+)*(.+)%$2Type%'

which will result in all anonymous types having names in the form <name>Type.

You can read more about options that control morphing of anonymous types
at the bottom of this page:

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


I will send you the binary with optimizations and support for anonymous
type morphing in a few minutes.


hth,
-boris
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 652 bytes
Desc: Digital signature
Url : http://codesynthesis.com/pipermail/xsd-users/attachments/20050922/5e22529a/attachment.pgp


More information about the xsd-users mailing list