Using XSD2CODE with multiple schema files
Asked Answered
A

1

6

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?

Alphard answered 21/2, 2012 at 23:6 Comment(0)
S
3

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

  • I'll leave my prev. answer below

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.

  • Note that since Employees.xsd already includes Person.xsd, you will only have to generate Xsd2Code for Employees.xsd.

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>
Sweetbread answered 22/2, 2012 at 1:1 Comment(6)
I don't understand how this helps me with multiple schema filesAlphard
I thought that auto-generating multiple files was the issue. I updated my answer.Sweetbread
AVIDeveloper - thanks for your update. Unfortunately this would require changes to the schema files, something not required by XSD. I have updated the question.Alphard
Sorry but this not the solution. maybe it is the solution for that simple case but if there is another xsd. lets say "managers.xsd" and it includes also "person.xsd". then if you generate "managers.cs", you will have same declarations again and Vs will return errors if same namespace. Ok maybe it is not a big job to strip off those manually but I am having really large xds and they include up to 4 child level. It gets really complicated. there must be a solution on that. I know it works for import but not with include! how?Torrell
@batmaci: In my updated response I write that "it doesn't seem that Xsd2Code was designed to handle more than one .xsd file at a time". Sorry I can't offer more than that.Sweetbread
Xsd2Code :=> Error: xsd2code++ community edition support only single schema. Include or import schemas are not supported. Please visit www.xsd2code.com for more details. What i will do if it will not make this job? Lost time!Tortile

© 2022 - 2024 — McMap. All rights reserved.