Comparison of Xsd Code Generators

Comparison of XSD Code Generators

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

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.

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.

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.

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:

  • 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

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:

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

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

  1. Regex replace - current project, case, whole word - [System.Runtime.Serialization.DataContractAttribute(Name:b*=:b*:q,:bNamespace: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 ,

Hope that helps someone.

How can I generate multiple classes from xsd's with common includes?

try the approach outlined here :
http://blog.hosca.com/blog/fpmlgen/

XSD generation from class, from code

how to generate xsd from class in code

Using XSD.exe.

without XSD.exe?

Why? Then you'll have to reinvent the wheel, or use a library.



Related Topics



Leave a reply



Submit