Incremental class generation from a set of referencing (include/import) XSD schemas

1.5k Views Asked by At

Let us assume, I have 3 XSD schemas:

  1. BaseSchema.xsd: contains reusable types e.g., position, colour, address, countrylist
  2. SchemaA.xsd: includes the base schema and is specific to domain A
  3. SchemaB.xsd: includes the base schema and is specific to domain B

I would like to generate their corresponding C# classes. I can run

  1. "XSD.exe /c SchemaA.xsd BaseSchema.xsd" + "XSD.exe /c SchemaB.xsd BaseSchema.xsd" resulting 2 C# files that containing the classes from BaseSchema 2x. Not good.
  2. "XSD.exe /c SchemaA.xsd SchemaB.xsd BaseSchema.xsd" which results only one C# class for the types in BaseSchema.xsd. This is very nice, but not always possible. For example, if I have to use a third party assembly already containing the generated class of BaseSchema and Schema B.

Is there a way to incrementally generate C# classes? E.g., by including assemblies somehow in the command line to instruct the generator reusing the already generated C# classes instead creating them again?

1

There are 1 best solutions below

2
On

Depending on the time and effort you want to put into this, I would

a) use "XSD.exe /c SchemaA.xsd SchemaB.xsd BaseSchema.xsd", delete the generated BaseSchema classes from the file and link to the third party lib instead.

b) use Xsd2Code. It doesn't do what you want out of the box but can be easily modified to your needs.

I don't think xsd.exe provides another suitable solution.