I have a flattened XSD here:
http://pastebin.com/tQVSH9Jp
I have a ‘substitution’ XSLT script I am running against it to fix it for XSD.exe (which ignores referenced elements), however the resultant XSD is missing a few properties. (ID is not present in UniqueID_Type).
Can anyone provide an XSLT script that will correctly perform these substitutions, or even provide another solution altogether?
It’s funny that someone suggested to write your own xsd.exe, and also to rely on XmlSchemaImporter… For one, I don’t think it is a trivial task; secondly, the problem with the missing attribute comes from XmlSchemaImporter; there’s a bug in ImportAttributeGroupMembers: instead of looking for an XmlSchemaAttributeGroupRef, it is checking for an XmlSchemaAttributeGroup (excerpt below courtesy of Reflector):
There’s a similar utility, xsd2code which I would try with the original XSD before going into XML Schema Refactoring (XSR).
If you want to go down this route, I recommend QTAssistant for XSR (I am associated with it). I’ve tried your XSD with the latest version (4.0.21) and it worked. I’ve posted the result here.
The generated code using XSD.exe for the fragment you pointed out as defective (I am just showing the fields) now shows the idField for the ID attribute:
What’s specific for your setup is the InlineAttributeGroups that must be set to true:
If you’re interested in more details about refactoring using QTAssistant, please take a look at this post, also on SO. Anyway, I’ve posted the entire refactored schema, feel free to use it…