Comparison of XSD Code Generators [closed]
Asked Answered
S

7

76

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

  • Must generate C# 2.0 code (or above), using generic collections where needed.
  • Must generate comments from the xsd comments
  • Must generate fully serializable code.
  • Should be able to generate resuable basetypes when generating from multiple xsd's with the same includes.

(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. 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)

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?

Sambar answered 22/12, 2008 at 12:31 Comment(2)
What kind of problems have you had with Xsd2Code? I haven't had any problems with it.Inotropic
on 5) #607585 has 2.0 XSDObjectGen link to sourceYoruba
A
62

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]+/// &lt;remarks/&gt; with ,
Adila answered 19/1, 2011 at 3:9 Comment(11)
I have to agree that Xsd2Code is currently the champ. Just watch out for the add-in not loading correctly if you have moved your default 'Documents' location, either manually or via GPO. Solution is to grab the add-in file from the install location and place it in the Documents\Visual Studio 2010\Addins\ folder.Carycaryatid
xsd2code seems dead. I hope a new version is forthcoming, there is a major blocking bug and a couple of other bugs that prevent us from using this realistically.Viviyan
Just a note: I came across XsdClassGen on Nuget (see nuget.org/List/Packages/XsdClassGen). It uses a T4 template, which is nice, but it's very primitive.Nonconductor
Added by Schalk Versteeg as edit: XSDtoClasses code.google.com/p/xsd-to-classes - Extendable VS plugin, very similar in capabilities to XSD2Code.Pisarik
XSD2Code doesn't work for Visual Studio 2012.Marylou
The data contract param /dc wasn't working for me until I used exactly the combination and order of params in this post: /pl Net35 /if- /dc /scBean
I would add that it does not properly handle attributes, and instead handles them the same as elements. There are workaround for data contracts to implement support for xml attributes that you will have to handle manually: #4859298Bean
Nov 2015 - The xsd2code site is still up, but no trial licenses are being issued and email to the site is bouncing. No updates since January. I think this vendor has abandoned the product.Stribling
The addin won't work in VS2015 (because it's an addin), but the library DLL is still compatible.Lieutenancy
For your information : marketplace.visualstudio.com/… The 5 stars Xsd2Code 2015 and 2017 integration has all the options we need with the dialog and generate our xml very nicely.Bacitracin
Xsd2Code is no longer freeScrofulous
J
9

I have not yet checked this out, but Linq2XSD might be a useful alternative.

I'm going to give this one a shot. LINQ with XSD generation would be better than any of these tools you mentioned - provided it works nicely.

Jillion answered 4/7, 2009 at 0:3 Comment(5)
don't be too concerned its a 'dead project'. if its pretty much complete and working then its not 'dead' - its working! seems ok for me so farJillion
I'm currently successfully using Linq to Xsd in an active project. It seems to be the most 'complete' xsd to class mapper that I've found. I tried using Xsd2Code, but it didn't map the complex types of the xsd very well - I had a xs:pattern restriction that is mapped perfectly in Linq to Xsd, but is missing in Xsd2Code. Top tip - download the source for Linq to Xsd - it has a whole bunch of docs and example projects that aren't listed in the 'documents' tab of codeplex - download hereSquinteyed
I've been using it a couple years now. It has some huge advantages over other entity technologies, and I think it's a real shame MS abandoned itJillion
Doesn't work with Visual Studio 2012.Marylou
Still using it! (Not for new stuff, but it still works under .NET Core).Jillion
P
3

OpenSource project XSD to Classes worked perfect for me.

Purveyance answered 4/8, 2011 at 15:46 Comment(0)
W
2

I a project a bit over a year ago we used CodeXS. With some minor adjustments (a script that cleaned up the generated code a bit) it worked a charm.

There is also Dingo, which have some very good extensibility features (which we didn't need).

Worktable answered 22/12, 2008 at 12:50 Comment(0)
P
2

Try OxmLibrary - http://oxmlibrary.codeplex.com

Presbyterian answered 5/12, 2010 at 22:14 Comment(0)
C
0

The best XSD class generator I've found is thinktecture WSCF.blue . It's nicer than most of the others for two reasons:

  1. Fixes naming. That means casing and plurization of types and property names.
  2. Creates a separate file for each class.

Or, if you're looking for a T4 solution, you can try XsdClassGen . This one isn't working for me. But the good news is that it's a T4 file, so it's easy to fix!

Combinative answered 20/10, 2011 at 0:57 Comment(0)
W
-2

Here is web based example of using XSLT to transform XML to C# code. The example takes a model (XML) that describes services (basically service names, namespaces, and list of operations), it then generates WCF services (interfaces, messages, faults, tests, etc) all in C#.net.

Wasserman answered 26/4, 2012 at 15:20 Comment(1)
The website is no longer available, and your answer is not useful either.Openfaced

© 2022 - 2024 — McMap. All rights reserved.