[xsd-users] Too many anonymous types

Brian Young ARA/CFD byoung at ara.com
Thu May 22 11:17:24 EDT 2008


I attempted your suggestion already, also to no avail. The XSD compiler
ran for a very long time, and then claimed to complete successfully,
however, it didn't produce any code (note I used this in conjunction
with -extern-xml-schema, let me know if this is a problem). Not sure
what happened there...

I have considered your first suggestion as well, just wanted to make
sure what I'm after couldn't be accomplished with --anonymous-regex
first. I was considering going a scripting/text replacement route, but
your xerces option is probably. I would love some help getting going, if
it wouldn't take long for you produce. One drawback may be that the
schema I working with is sensitive. So I wouldn't be able to send you
the test case.

Thanks for a quick response!


-Brian Young <brian.young at ara.com>

-----Original Message-----
From: Boris Kolpackov [mailto:boris at codesynthesis.com] 
Sent: Thursday, May 22, 2008 10:40 AM
To: Brian Young ARA/CFD
Cc: xsd-users at codesynthesis.com
Subject: Re: [xsd-users] Too many anonymous types

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