[xsd-users] Splitting a long schema with <include> fails

Boris Kolpackov boris at codesynthesis.com
Fri Nov 9 08:52:07 EST 2012


Dan,

In the future please keep your replies CC'ed to the xsd-users mailing
list as discussed in the posting guidelines:

http://www.codesynthesis.com/support/posting-guidelines.xhtml

Johnston, Dan <Daniel.Johnston at nrc-cnrc.gc.ca> writes:

> I tried xsd.exe with the root schema only 
>
> "C:\Program Files (x86)\CodeSynthesis XSD 3.3\bin\xsd.exe" cxx-parser 
> --prologue "// Copyright NRC" --generate-polymorphic --root-element-last
> --force-overwrite definitionschema.xsd
> 
> It will generate code only for the elements defined in the root schema
> (the header and sub-components: version, description, etc.)

Right, in the file-per-schema mode each schema must be compiled separately.


> I then tried with only the second (included) schema file
>
> "C:\Program Files (x86)\CodeSynthesis XSD 3.3\bin\xsd.exe" cxx-parser 
> --prologue "// Copyright NRC" --generate-polymorphic --root-element-last
> --force-overwrite parmeshschema.xsd
> 
> The error message was "base type 'DefinitionFile' was not found"

Right, parmeshschema.xsd references DefinitionFile but does not include its
definition. Note that including definitionschema.xsd in parmeshschema.xsd
would create a circular dependency between the two. While valid in XML Schema
and XSD can handle some cases (while for others you will need the file-per-
type mode), this is, IMO, bad design and I wouldn't recommend it.


> I then tried with both schema files on the command line
> "C:\Program Files (x86)\CodeSynthesis XSD 3.3\bin\xsd.exe" cxx-parser 
> --prologue "// Copyright NRC" --generate-polymorphic --root-element-last
> --force-overwrite definitionschema.xsd parmeshschema.xsd
> 
> I got the same error message. 

Right, there is no difference.


> I then tried with the option "--file-per-type".  
> "C:\Program Files (x86)\CodeSynthesis XSD 3.3\bin\xsd.exe" cxx-parser 
> --prologue "// Copyright NRC" --generate-polymorphic --root-element-last
> --file-per-type --force-overwrite definitionschema.xsd
> 
> This created skeleton header and cpp files for ALL the elements in the
> root schema and in the included (parmesh, derived) schema.  I just have
> to deal with all those small files, but I will be using CMake to automate
> this.

Yes, the file-per-type mode will do what you want at the expense of all
the files and compilation times. If you decide to go this route, you may
find the --file-list* options useful.


> B.T.W. I was generating the print implementations and sample driver
> only to check against the application classes that are derived from
> these skeleton classes. My application 'driver' is actually a base
> class with a method that will call the document constructor with the
> polymorphic third parameter set to 'true'.

Calling the document constructor is only a small part of supporting
polymorphism. You will also need to create parser maps, etc. See the
'polymorphism' example for details.


> Any better suggestions?

I would suggest that you get rid of the mutual dependency between
your schemas and then use the file-per-schema mode.

Boris



More information about the xsd-users mailing list