views:

1444

answers:

3

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?

+5  A: 

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.

John Feminella
Actually, XSD can generate classes in C#, VB.NET, JScript, or C++. See the /language switch.
John Saunders
Sorry, I didn't mean to imply that it couldn't. His question only concerned C# classes. But yes, the /language switch is handy.
John Feminella
You don't have to have Visual Studio. XSD.EXE is part of the .NET SDK.
Joel Mueller
+1  A: 

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

Cheeso
+1  A: 

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.

User1