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:
<snip>
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:
<snipped a W3C Schema>
When you can do one of these:
<snipped Ruby class definitions

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.

<snip> 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 <geoff@xxxxxxxxxxx>





.



Relevant Pages

  • Re: Godels comments about the "true reason" for incompleteness
    ... refuted the schema P&~P->Q ... refute that schema by proving a contradiciton. ... PA refutes EVERY sentence in the language of PA if PA ... Under your notion of 'consistency sentence', in first order, any valid ...
    (sci.logic)
  • Re: noobq: closure-based web stuff
    ... >> Ken Tilton wrote: ... >> I think the next step up in persistence is going to have to: ... allow for either flexible schema, or no schema, a la ...
    (comp.lang.lisp)
  • Re: non-Archimedean models of Euclidean geometry?
    ... making an axiom schema in which A and B are defined by first-order ... The axiom basically says that if every point in A is to the ... question or definable in that language. ... "Understanding Godel isn't about following his formal proof. ...
    (sci.logic)
  • Re: Finite schema?
    ... Supposing you're working with a language with a different ... over classes and this axiom being a finite schema? ... The comprehension schema restricted to formulas without bound class variables ...
    (sci.math)
  • Re: Godels comments about the "true reason" for incompleteness
    ... where P and Q are arbitrary) into the language ... yield that every first order theory proves EVERY tautology in the ... INSTANCES of a schema have truth values, ...
    (sci.logic)