tags:

views:

87

answers:

2

I am using xsd2code to generate classes from the xsd schema provided by the star standard.

I did try to use xsd.exe to generate the classes, but it did not do a good job.

When I generate the class from 'ProcessCreditApplication.xsd' it generates a single file with all the needed classes. Everything works fine at this point.

When I generate another xsd, ConfirmBOD.xsd I get ambiguity errors, as both files contain the same base classes.

For example both files generate a 'Description' class. Because both file are in the same namespace there is ambiguity between the two classes in the same namespace.

Is there a way to generate classes from multiple xsd such that sub classes are not duplicated?

My only thought to get around this problem is to but each generated file in its own namespace. This is not ideal but works.

I would like to use xsd.exe as it seems to take multipliable files, but the code it generates does not work for my needs.

Update I tried Linq to xsd, and it did not work. It complained that same types have 'already been declared'.

For reference: here is where I am getting the schema's:

http://www.starstandard.org/SIGXMLSTAR4/XMLSchemas http://www.starstandard.org/uploads/SIGXMLSTAR4/STARSchemaRepository_Rev444.zip

+1  A: 

I've had issues using xsd.exe as well. I've had success using Microsoft's LinqToXsd project to generate C# code from XSD files. I haven't tried it with extremely complex XSD files, but you may give it a shot.

The LinqToXsd project is open source on CodePlex

The command line usage syntax is:

LinqToXsd <schemaFile> [one or more schema files] [/fileName:<csFileName>.cs] [/lib:<assemblyName>] [/config:<configFileName>.xml] [/enableServiceReference] [/nameMangler2]
bporter
A: 

I think there are really only two choices:

  1. Use a different namespace for each generated file.
  2. Give all your types unique names (probably not an option for your situation).

If you think about it, each generated file is actually a bunch of classes, not just one class, so it actually makes sense to give each its own namespace.

DanM