将XSD2CODE与多个模式文件一起使用

Jon*_*ats 5 .net xsd2code

我正在使用XSD2CODEVisual Studio 2010.我知道我可以右键单击schema(XSD)文件并从中生成c#类.

我想知道的是,当我有一个XML文件的两个模式文件时,如何生成C#类?

更多信息:

也许我在原始问题中没有提供足够的细节.

引用问题为什么XSD.EXE创建两个.XSD文件,以及如何使用它们?,我基本上是在问同一个问题XSD2CODE而不是XSD.

使用XSD我会使用命令:

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

如何XSD2CODE在VS 2010 GUI和/或命令行中执行此操作?

AVI*_*per 3

编辑:
为了回答更新的问题,Xsd2Code 似乎并不是被设计为一次处理多个 .xsd 文件。

我从以下地方收集到这一点:

  1. 命令行语法
    Xsd2Code.exe <XSD File> [Namespace] [Output file name] [Options]
  2. 快速浏览源代码(从http://xsd2code.codeplex.com/SourceControl/list/changesets下载版本 88331并查看Trunk\Xsd2Code.Console\EntryPoint.cs.

Pascal Cabanel 在 Xsd2Code 的 CodePlex 网站上似乎非常活跃。考虑联系他以获得明确的答案: http ://www.codeplex.com/site/users/view/pcabanel

  • 我会留下我的上一个。回答如下

为了自动创建支持的 xsd2Code 类文件,您可以在“解决方案资源管理器”中单击 .xsd 文件,然后在“属性”窗口中将Xsd2CodeCustomTool写入/粘贴到“自定义工具”属性中。

为了在另一个 .xsd 文件中“查看”一个 .xsd 文件的数据类型,您可以使用一条include语句。

下面是一个包含数据定义的 Person.xsd 示例,以及Employees.xsd include-ing Person.xsd 并使用该Person数据类型。

  • 请注意,由于Employees.xsd 已包含Person.xsd,因此您只需为Employees.xsd 生成Xsd2Code。

人物.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>
Run Code Online (Sandbox Code Playgroud)

员工.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>
Run Code Online (Sandbox Code Playgroud)