From: Geoffrey Lane Date: 2006-02-24T22:27:52+09:00 Subject: Re: Creating Ruby Classes from XSD? On Feb 23, 2006, at 4:59 PM, Henrik Martensson wrote: > On Thu, 2006-02-23 at 18:32, Logan Capaldo wrote: > >> Ok, I'm going to be honest and say first I've never had occasion to >> use this tool. But I'm wondering what exactly is the point? Ruby's >> syntax is much less verbose than XML. >> Why would you want to type this: > >> When you can do one of these: > > >> I may have mangled some of the XSD, I'm admitedly not familiar with >> it, but generating classes froma schema seems rife with problems >> > > The basic idea is that if you have a schema specification, you can > generate classes for whatever language you want, and the applications > that use them will all understand the same data formats. > > Building classes directly from a data format specification > makes the application using the classes tightly coupled to the data > format. Yep, that's the exact idea. You don't only want to be tightly-coupled to the data specification, you want it to be EXACTLY the same. The most common place this is used is in SOAP Web Service design. It's often called contract first or schema first design. It's not a bad thing to be tightly coupled to your data at that point because the whole idea is to be able to interoperate with an existing service. This is all about sharing, and it's nice to make things easy and language-neutral when you're going to share. (Cue up Mr. Rogers theme music.) XSD schema (for all of its imperfections) has the ability to specify constraints on the data that help validate it. Up front your service can define things like: (pseudo-XSD) US Address: Street1 = required Street2 = optional City = required State = [A-Z]{2} USZip = [0-9]{5}(-[0-9]{4})? Those kinds of constraints can be done in code, but no language I know of can make an interface to a method that explicit. -- Geoff Lane