多个 XSD 架构文件到 C# 类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1140495/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Multiple XSD schema files to C# classes
提问by Ray Lu
What is the best way to generate C# classes from multiple XSD schema files?
从多个 XSD 架构文件生成 C# 类的最佳方法是什么?
Some XSD schema files may have dependency to the other, I am trying to avoid duplicated C# classes being generated.
一些 XSD 架构文件可能依赖于另一个,我试图避免生成重复的 C# 类。
采纳答案by John Saunders
Use the XSD.EXE program, but pass allof the schemas to the program on the same command line.
使用 XSD.EXE 程序,但在同一命令行上将所有架构传递给该程序。
For example:
例如:
> xsd /c qbxmltypes130.xsd QBUqbxmlops130.xsd QBUqbxmlso130.xsd QBUqbxml130.xsd
Will emit a class named:
将发出一个名为:
qbxmltypes130_QBUqbxmlops130_QBUqbxmlso130_QBUqbxml130.cs
In this case these are Quickbooks Desktop SDK xsd files, and the final file has types it depends on in the first 3 files. It won't emit on its own, but with its dependencies it works as desired.
在这种情况下,这些是 Quickbooks Desktop SDK xsd 文件,最终文件在前 3 个文件中具有依赖的类型。它不会自己发射,但它的依赖关系可以按需要工作。
Note that there is a /parameters:<file>
switch that allows you to specify a file of command line parameters. I remember using it in one project for a similar reason.
请注意,有一个/parameters:<file>
开关允许您指定命令行参数文件。我记得出于类似的原因在一个项目中使用它。
XSD.EXEdoc has the parameter format.
XSD.EXE文档具有参数格式。
回答by anony mouse
I for one found the examples in the MSDN doc a bit lacking. Here's an example parameters file for the issue codemeit described:
我发现 MSDN 文档中的示例有点缺乏。这是所描述的问题代码的示例参数文件:
<xsd xmlns='http://microsoft.com/dotnet/tools/xsd/'>
<generateClasses language='CS' namespace='Namespace.subnamespace'>
<schema>FirstSchema.xsd</schema>
<schema>AnotherSchema.xsd</schema>
<schema>LastSchema.xsd</schema>
</generateClasses>
</xsd>