[xsd-users] Too many anonymous types
Boris Kolpackov
boris at codesynthesis.com
Thu May 22 10:39:37 EDT 2008
Hi Brian,
Brian Young ARA/CFD <byoung at ara.com> writes:
> I am new to XSD, and trying to use this tool to generate some code for a
> large schema (3+ MB). However the generated code overwhelms the VS2005
> compiler with lots of issues. The main one I can't seem to get passed is
> too many objects exported from a DLL/library, as mentioned here:
> http://support.microsoft.com/kb/949945.
>
> I tried various things like manually moving the parsing & serialization
> code into a separate lib, to no avail.
>
> So I dug in further and what I find is many, many types are being tagged
> as anonymous which I didn't expect. The result is alot of duplication.
> In some cases 30 or more separate class definitions for the same
> data/type.
>
> To illustrate the issue I have with the schema I am working with (which
> I didnt develop), I have simplied the schema and pasted it below. If you
> run it through the xsd tool, you'll see generated classes "complexType1"
> and "complexType2" which is correct. But, you'll also see 2 classes
> "anonType" and "anonType1" which are essentially the same. My goal is to
> get a single "group1" class rather than 2 separate "anonType" &
> "anonType1" classes.
>
> [...]
>
> Any suggestions? Is there a way to get the 'group ref' taken into
> consideration when determining if a type is anonymous?
The groups are a syntactic sugar in XML Schema and are treated as
such by the XSD compiler. Once it is time to generate the code,
the internal schema model has all group ref's substituted with
the actual content of the groups. So there is no out of the box
way to get rid of this bloat.
I see a couple of potential ways to deal with it. You can create
a small preprocessor for the schema which finds all such equivalent
types and substitutes them with the named ones (this will result in
a semantically equivalent schema). For example you can use Xerces-C++
to load the schema into DOM (unfortunately you cannot compile
XMLSchema.xsd to get its C++ object model ;-)) and then inject a
named complex type for each group in your schema. Then you can
go over and replace each anonymous type that just contains a group
with the named type reference. I can help you write something like
this if you like.
The other approach is to use the file-per-type compilation mode
which will result in a separate set of source files being generated
for each type defined in your schema. You can then package them
into several DLLs. However, looking at the size of your schema,
I think it will be pretty hard to maintain. For more information
on the file-per-time mode see this blog post:
http://www.codesynthesis.com/~boris/blog/2008/02/13/codesynthesis-xsd-3-1-0-released/
Boris
More information about the xsd-users
mailing list