XSD code发电机的比较 [英] Comparison of XSD Code Generators

查看:184
本文介绍了XSD code发电机的比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做从XSD模式文件在code产生了一些研究。
我的要求:

I'm doing some research in code generation from xsd schema files. My requirements:


  • 必须生成C#2.0 code(或以上),使用泛型集合需要的地方。

  • 必须生成从XSD评论评论

  • 必须产生完全序列化code。

  • 应该可以从多个XSD的使用相同的生成包括何时生成可重复使用的基本类型。

(另见我的其他问题:<一href=\"http://stackoverflow.com/questions/374600/how-can-i-generate-multiple-classes-from-xsds-with-common-includes\">How我可以生成从XSD的共同包括?和<多类href=\"http://stackoverflow.com/questions/374086/how-can-i-generate-comments-from-xsdocumentation-tags-in-a-wsdl\">How我可以生成从XS评论:在WSDL文档标记

(see also my other questions: How can I generate multiple classes from xsd’s with common includes? and How can I generate comments from xs:documentation tags in a wsdl?

我已经找到了以下选项:

I have found the following options:


  1. 使用XSD.EXE(与SDK和Visual Studio提供)

  2. XSD codeGEN从丹尼尔Cazzulino

  3. Xsd2 code

  4. codeXS

  5. XsdObjectGen微软

  6. XSDClassGen (好像在行动中失踪)

  1. Use xsd.exe (supplied with the SDK and Visual Studio)
  2. XSDCodeGen from Daniel Cazzulino
  3. Xsd2Code
  4. CodeXS
  5. XsdObjectGen by Microsoft
  6. XSDClassGen (Seems to be missing in action)

我错过任何?因为(1),(2)和(5)不产生2.0 code和我有从序列化code的问题(3)。产生code,当你用什么?

Did I miss any? Because (1), (2) and (5) do not generate 2.0 code, and I have problems with serializing code from (3). What do you use when generating code?

推荐答案

我相信 XSD2 code 是目前(2011年)的最佳工具。

I believe XSD2Code is the best tool currently available (in 2011).

我最近通过同样的流程去在分析现有工具,在那里工作,所以我想我会提供更新的答案,涉及到的 VS2010

I recently went through the same process at work of analysing the available tools out there so i thought i would provide an updated answer that relates to VS2010.

我们的主要驱动力是, XSD.EXE 不会产生从XSD注解,这是我们想要的XML文档,因为我们有数以百计的类型定义。我试着上面列出的所有工具以及其他大部分要么去precated,无人维护或无法匹配XSD.EXE可用的当前功能在VS2010。

Our main driver was that xsd.exe does not generate XML doc from the XSD annotations, which we wanted as we have hundreds of type definitions. I tried all the tools listed above as well as others and most were either deprecated, unmaintained or unable to match the current functionality of xsd.exe available in VS2010.

Xsd2 code 不过是一个极好的工具,似乎是积极的维护。它提供了上面所列出的所有功能和更多 - 在codePLEX页面也有各种选择如何影响输出很好的例子。

Xsd2Code however is a superb tool and seems to be actively maintained. It provides all the functionality that was listed above and a lot more - the CodePlex page also has great examples of how the various options affect output.

它也有紧密的VS集成,包括上下文菜单集成和自定义生成工具(这意味着如果你引用的XSD在你的项目,并指定自定义工具,它会自动为您更新更新code XSD)。总而言之,我们节省了大量的工作。

It also has tight VS integration, including context menu integration and a custom build tool (which means that if you reference the XSDs in your project and specify the custom tool, it will automatically update the code as you update the XSD). All in all saved us a lot of work.

其他工具我看着简要总结:

A quick summary of the other tools i looked at:


  • 野狗 - 似乎更对齐到Java

  • XSD codeGEN - 更多关于如何编写自定义生成工具演示

  • codeXS - 一个相当不错的工具,但不融合,功能和不再维护

  • XSDObjectGen - 不再维护,比目前XSD.EXE官能度

  • XSDClassGen - 无法找到它

  • OXM库 - 推荐在看这个项目,维护和强大的功能

  • 的LINQ to XSD - 非常的项目,但不是我一直在寻找

  • Dingo - Seems to be more aligned to Java
  • XSDCodeGen - More of a demo on how to write a custom build tool
  • CodeXS - Quite a good tool, but less integration, features and no longer maintained
  • XSDObjectGen - No longer maintained, less functionality than current xsd.exe
  • XSDClassGen - Could not locate it
  • OXM Library - Recommend looking at this project, maintained and great functionality
  • LINQ to XSD - Very cool project, but not what i was looking for

附录:
如果你决定XSD2 code继续前进,还有我发现了一些问题与命令行工具的工作。特别是,与参数的处理需要一些参数是按照一定的顺序,以及一些无证依赖的一些错误(例如 - 自动参数及放大器; .NET版本是为了具体而定)。以下是我用来生成使用XSD2 code,然后清除输出中的code步骤 - 采取必要适用于您的位:

Addendum: If you do decided to go ahead with XSD2Code, there are a number of issues i found working with the command-line tool. In particular, there are some bugs with the argument processing that require some arguments to be in a certain order as well as some undocumented dependencies (eg - automatic parameters & .NET version are order specific and dependent). The following are the steps i used to generate the code using XSD2Code and then cleanup the output - take the bits that apply to you as necessary:

运行以下批处理文件来生成初始code,改变路径到正确的位置:

Run the following batch file to generate the initial code, changing the paths to the correct locations:

@echo off

set XsdPath=C:\schemas
set OutPath=%XsdPath%\Code
set ExePath=C:\Progra~1\Xsd2Code
set Namespace=InsertNamespaceHere

echo.Starting processing XSD files ...
for /f %%a IN ('dir %XsdPath%\*.xsd /a-d /b /s') do call:ProcessXsd %%a

echo.Finished processing XSD files ...
echo.&pause&
goto:eof

:ProcessXsd
%ExePath%\Xsd2Code %~1 %Namespace% %XsdPath%\Code\%~n1%.cs /pl Net35 /if- /dc /sc /eit
echo.Processed %~n1
goto:eof

根据需要执行以下步骤来收拾产生code,

Perform the following steps to tidy up the generated code, as necessary:


  1. 正则表达式替换 - 当前项目,案例,整个单词 - [System.Runtime.Serialization.DataContractAttribute(名称:B * =:b *的Q,:b *的命名空间:B * =:B * {: q})使用[DataContract(命名空间= \\ 1)]

  2. 替换 - 当前项目,案例,整个单词 - [System.Runtime.Serialization.DataMemberAttribute()] [数据成员]

  3. 正则表达式替换 - 当前项目,案例,整个单词 - System.Nullable \\&LT; {:W}> \\ 1 \\

  4. 正则表达式替换 - 打开的文档,案例,整个单词 - {:W}类型 \\ 1

  5. 替换 - 打开的文档,案例,整个单词 - 的System.DateTime 日期时间,然后添加using语句缺少

  6. 替换 - 打开的文档,案例,整个单词 - [System.Xml.Serialization.XmlIgnoreAttribute()] [XmlIgnore]

  7. 替换 - 当前项目 - System.Xml.Serialization.XmlArrayAttribute XmlArray

  8. 替换 - 当前项目 - System.Xml.Serialization.XmlArrayItemAttribute XmlArrayItem

  9. 正则表达式替换 - 当前项目 - [:WH] + /// \\&LT;言论/ \\&GT;

  1. Regex replace - current project, case, whole word - [System.Runtime.Serialization.DataContractAttribute(Name:b*=:b*:q,:b*Namespace:b*=:b*{:q})] with [DataContract(Namespace = \1)]
  2. Replace - current project, case, whole word - [System.Runtime.Serialization.DataMemberAttribute()] with [DataMember]
  3. Regex replace - current project, case, whole word - System.Nullable\<{:w}> with \1\?
  4. Regex replace - open documents, case, whole word - {:w}TYPE with \1
  5. Replace - open documents, case, whole word - System.DateTime with DateTime, then add missing using statements
  6. Replace - open documents, case, whole word - [System.Xml.Serialization.XmlIgnoreAttribute()] with [XmlIgnore]
  7. Replace - current project - System.Xml.Serialization.XmlArrayAttribute with XmlArray
  8. Replace - current project - System.Xml.Serialization.XmlArrayItemAttribute with XmlArrayItem
  9. Regex replace - current project - ,[:Wh]+/// \<remarks/\> with ,

希望有所帮助别人。

这篇关于XSD code发电机的比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆