Hi,
I am using the xsd.exe tool (in .NET 2.0) to generate C# classes from a set
of schemas. Some of the XML types that I have defined are used by more than
one schema. For maintenance purposes, I have placed these “common” types
into their own schema and have imported them into the other schemas as
needed. As a simple example, I have something like the following:
Type1.xsd - defines a type called Type1
Type2.xsd - defines a type called Type2 that has sub-elements of type
Type1. Imports Type1.xsd.
Type3.xsd - defines a type called Type3 that has sub-elements of type
Type1. Imports Type1.xsd.
When I generate the classes from these schemas, I would like to place the
class generated from Type1 into its own .cs file and into a namespace that is
different from the namespaces of Type2 and Type3. I would like the
generated .cs file for Type2 to define only the class that corresponds to
Type2. I do not want the .cs file to also define Type1. Instead, I would
like it to generate the correct using statement for the Type1 namespace (or
fully qualify the references to Type1 within the code of Type2). Similarly,
I would like the generated .cs file for Type3 to define only the class for
Type3 and the correct using statement or fully qualified names for Type1.
The output I describe above would more closely match the class organization
I would create by hand if I was not generating the classes from a schema. By
doing so, I could then include Type1 in its own assembly, for example.
My problem is, as far I can tell, I cannot get xsd.exe to do this. It
insists on defining all classes required by a type in a single .cs file. So
the .cs file that is generated for Type2 defines both Type2 and Type1. The
output generated for Type3 defines both Type3 and Type1. As a result, I now
have Type1 defined multiple times, and each one of these instances is
considered a different type.
Is there any way to control the output of xsd.exe as I describe above? I
tried using the /element option, but this does not seem to help. I can hand
modify the generated .cs files after running xsd, but I’d like to avoid this
if possible.
Thanks in advance.