From: Richard Kilmer Date: 2003-03-19T16:01:53+09:00 Subject: Re: XML too hard (YAML opportunity?) On Wednesday, March 19, 2003, at 01:27 AM, wrote: >> jbritt@ruby-doc.org wrote: >> >>> YAML has its place, though personally I haven't had a need for >> a statically-typed markup language (and I admit I still haven't >>> managed to finish reading the spec). But it can't (so far, at >> least) stand in for XML; comparisons between the two are apples and >>> oranges. >> >> What does statically typed mean here? > > I mean the data carries with it instructions on how it is to be > processed. > It says "Process me as a String," or, "Process me as a Hash." > > I don't usually want that in my data files. It tends towards > application > logic. > So the fact is the parser of YAML infers (through rules) the types of the elements it parses is bad from your perspective? The issue is SOMETHING has to know this. Its either written in some parser function and mapped (from XML) into your internal object structure, or read in directly from YAML. As we did with FreeRIDE, the classes that are serialized to YAML are, in fact, utility classes that YAML is serializing for us. We just maintain those files (in Ruby). This is far better than writing an emitter/parser pair for an XML format. I get to code in my language...and don't worry about the data format. Think of it this way: class Person attr_accessor :firstname, :lastname end p = Person.new p.firstname = "Richard" p.lastname = "Kilmer" === Output === XML: #BUILD EMITTER class Person def to_xml "" end end xml = person.to_xml puts xml YAML: yaml = person.to_yaml puts yaml --- !ruby/object:Person firstname: Richard lastname: Kilmer === Input === XML: # BUILD PARSER class Person def Person.from_xml(xml) doc = REXML::Document.new(xml) p = Person.new p.firstname = doc.root.attribute['firstname'] p.lastname = doc.root.attribute['lastname'] return p end end p = Person.from_xml(xml) YAML: p = YAML.load(yaml) ........ And now, add some new properties: class Person attr_accessor :firstname, :lastname, :middle, :age, :hair_color, :eye_color end Here is what you do with YAML: p = Person.new p.firstname = "Richard" p.lastname = "Kilmer p.hair_color = "Brown" yaml = p.to_yaml p2 = YAML.load(yaml) In XML we have to update our emitter and parser. ....... -rich