.netxsd2code

Using XSD2CODE with multiple schema files


I am using XSD2CODE with Visual Studio 2010. I know I can right click on a schema (XSD) file and generate the c# class from it.

What I would like to know is how can I generate the C# class when I have two schema files for a single XML file?

More information:

Perhaps I did not provide sufficient details in my original question.

Referencing question Why does XSD.EXE Create Two .XSD Files, and How to Use Them? , I am basically asking the same question for XSD2CODE instead of XSD.

With XSD I would use the command:

D:\>xsd response.xsd response_app1.xsd /classes

How do I do this with XSD2CODE, both in the VS 2010 GUI and/or the command line?


Solution

  • EDIT:
    To answer the updated question, then it doesn't seem that Xsd2Code was designed to handle more than one .xsd file at a time.

    I gather this from:

    1. The command-line syntax
      Xsd2Code.exe <XSD File> [Namespace] [Output file name] [Options]
    2. A quick browse at the source code (download build 88331 from http://xsd2code.codeplex.com/SourceControl/list/changesets and look into Trunk\Xsd2Code.Console\EntryPoint.cs.

    Pascal Cabanel seems to be pretty active on Xsd2Code's CodePlex site. Consider contacting him for a definite answer: http://www.codeplex.com/site/users/view/pcabanel


    In order to automatically create the supporting xsd2Code class files, you can click the .xsd file in the Solution Explorer and in the Properties window, write/paste Xsd2CodeCustomTool into the "Custom Tool" property.

    In order to "see" data types from one .xsd file in the other, you can use an include statement.

    Here's an example with a Person.xsd containing a data definition and Employees.xsd include-ing Person.xsd and consuming the Person data type.

    Person.xsd

    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
               targetNamespace="CommonNamespace"
               xmlns="CommonNamespace"
        >   
        <xs:complexType name="Person">
            <xs:sequence>
                <xs:element name="Name" type="xs:string"/>
            </xs:sequence>
        </xs:complexType>
    </xs:schema>
    

    Employees.xsd

    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
               targetNamespace="CommonNamespace"
               xmlns="CommonNamespace"
        >
        <xs:include schemaLocation="Person.xsd"/>
    
        <xs:element name="Employees">
            <xs:complexType>
                <xs:sequence>
                    <xs:element name="Employee" type="Person" maxOccurs="unbounded"/>
                </xs:sequence>
            </xs:complexType>
        </xs:element>
    
    </xs:schema>