Workshop : XML Schemas + Object Models

Actually, very few .Net developers that I’ve worked with know what a typed DataSet is let alone how to create one. It’s one of those perplexing things that always baffles me as typed DataSets are not a bad way to make the best of the flexibility of DataSets while still offering design time support and comiple time error checking (to some degree, of course).

At the core of the typed DataSet is an XML schema that describes the types and structure of the DataSet. While typed DataSets are great, if you ever look at the code, it’s quite heavy and not necessarily the most optimized structure for over the wire transport. As even the discussion of typed DataSets narrows down the audience of developers that know how to work with schemas to generate a typed DataSet, the concept of generating entire object models using XML schemas is even less understood. Yes, indeed, the XSD.exe tool that ships with Visual Studio.Net can also be used to generate object classes from the same schemas (although they are a bit clumsy to work with).

You may be asking yourself why bother with schemas when you can just create the classes by hand or some other sort of visual code generation tool. Well, for some people (myself included), schemas seem a very natural way to express object models and classes. I mean, after all, the purpose of a schema is to define what an object (typically an XML document) looks like. But certainly, if that was it, it wouldn’t really be worth the effort, now would it? For me, there is an added benefit in that it’s very easy to define typed collections in schemas. On top of that, the generated classes come with various XML attributes already marked up for you, which is handy if you plan on using the classes as data transfer objects for your web service.

If you’re interested, check out the workshop.

Leave comments, questions, and criticisms in the thread.

You may also like...