Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jaxb equivalent in C#

Using JAXB in Java it is easy to generate from a xml schema file a set of Java classes that xml conforming to that schema can be deserialized to.

Is there some C# equivalent of JAXB? I know that Linq can serialize and deserialize classes to/from xml files. But how can I generate C# classes from xml schema file and then use this classes with linq?

like image 723
mgamer Avatar asked Apr 19 '09 13:04

mgamer


3 Answers

If you're using Visual Studio, try the XML Schema Definition Tool. It takes your schema definitions and produces C# classes -- or it can go the other way and produce schema definitions from classes. It also has a number of other XML-related transformations.

like image 170
John Feminella Avatar answered Nov 16 '22 04:11

John Feminella


There is a better tool from Microsoft called XsdObjectGen, the XSD Object Code Generator. It is like xsd.exe, but better. Also free, it is not part of the .NET SDK, but is a separate download.

Also see the SO question: XSDObjectGen vs Xsd.exe

like image 38
Cheeso Avatar answered Nov 16 '22 03:11

Cheeso


Look into using DataSet. It's a bit of a different concept from using "Java Beans". The entire XML document is treated hierarchical set of tables all in a single class. The good part is that theory of encapsulation for OOP is actually enforced. Wow, Microsoft got something right that Sun pooched.

Anyway. You can also look at typed DataSet's if you want make things more interesting. I've used this on major projects with great success.

like image 30
User1 Avatar answered Nov 16 '22 02:11

User1