I have inherited a collection of 148 XSD files, and have been asked to generate a .Net assembly with types that represent those lais out in the XSDs. Several of these XSDs import others within the collection that represent common types. My first
attempt was with XSD.exe, but I had several problems with that, not the least of which was a real problem referencing external XSDs.
Then I found this wonderful post:
http://hosca.com/blog/post/2008/12/26/Generating-C-classes-from-FpML-Schema.aspx
This helps a lot with the external XSDs, but doesn't help me very much in the fact that it assumes that all of the types are referenced in a single root schema. I am not so lucky, so I'm working on extending this code to do what I want.
Let's say I have three schemas (each with it's own unique namespace): common.xsd, general.xsd and specific.xsd:
common.xsd defines shared types: typea, typeb and typec
general.xsd imports common.xsd and provides complex types based on those: gentypex, gentypey and gentypez
specific.xsd imports both common.xsd and general.xsd and provides types that extend them: foo and bar
If I use the code in the link above, generating a code file for each xsd, then the types in common.xsd are generated in each file, and if the files are combined into a single project, it won't compile sue to the duplicate definitions of those types.
So, what I want is three code files that have appropriate namespaces that utilize the "using" syntax and not generate the shared types within the file. The result of the example above would result in:
common.cs:
typea
typeb
typec
general.cs:
using common;
gentypex
gentypey
gentypez
specific.cs:
using common;
using specific;
foo
bar
I found the SchemaImporterExtension class (http://msdn.microsoft.com/en-us/library/ms163218(v=VS.90).aspx) and it shows an example for spewing the using directives (and an
assembly reference, which I won't need), but alas, the type is still generated into my code file, thus negating the effect of the "using".
I'm still trying to figure this out, but thought I would toss this out into the ether to see if anyone else had any bright ideas.
Thanks,
Todd