From: Henrik Martensson Date: 2006-02-25T01:29:16+09:00 Subject: Re: Creating Ruby Classes from XSD? On Fri, 2006-02-24 at 05:42, Dave Cantrell wrote: > Henrik Martensson wrote: > > Unfortunately, the idea is flawed. You are quite right. There isn't much > > of a point. Building classes directly from a data format specification > > makes the application using the classes tightly coupled to the data > > format. > > ActiveRecord? > > I've never used Rails and have been in limbo for 2 weeks learning Ruby > due to work swampage, but it seems from everything I read that > ActiveRecord does exactly what you are coming out against, and does it > very well. No, I have nothing against ORM tools. ActiveRecord, (which I must confess I haven't used, just poked at while playing with Rails a while ago,) provides an interface between a data source layer and a business layer, and that is fine. Couldn't manage relational databases without ORM. (Still, there are XML databases that you can query with XPath or XQuery, and get an XML message from when they reply. This approach does have practical problems (like abysmal performance), but when you are dealing with hierarchical information it is a pretty neat approach.) An ORM tool provides a way to make objects persistent and bridges the data source layer and the business layer in an application. This is good. A schema to code generator creates a tight coupling between a document (or 'message') format and business logic. It is often used in client applications to generate code that couples the application tightly to a data format _owned_by_somebody_else_. This is bad. If I build a SOAP service, and you build a client and generate classes from the WSDL I provide, then your application will break every time I change the data format. On the other hand, if I offer a REST service, and you build an application that uses LibXML to mine the messages for the information you need, then I can add new stuff to the dataformat without breaking your application. Consider an XML editor. An XML editor uses an internal representation of XML documents that is generic. For example, XMetaL uses DOM, and you can use the editor to edit XHTML, DocBook, XSEIF, TIM, TEDD, TEI, or whatever you like. If the editor had been written using a code generator to map from a schema to an internal representation that is specific to that one format, then the editor would only have been able to handle one format. For example, you would get an XHTML editor that could not handle DocBook or TEI. If you wanted to use a new format, you would need a new editor. (Plenty of editors are built that way. It is still not a good idea.) /Henrik -- http://kallokain.blogspot.com/ - Blogging from the trenches of software development http://www.henrikmartensson.org/ - Reflections on software development http://testunitxml.rubyforge.org/ - The Test::Unit::XML Home Page http://declan.rubyforge.org/ - The Declan Home Page