[WhyTheLuckyStiff] Herein find the EchoExample translated to a YAML equivalent. This may be a little off, as there is much to take in from around this wiki, so some of the semantics may be lost in the translation. I take a few liberties, pluralize a few words.
This document does not intend to sway the populace towards accepting YAML as Echo's underlying syntax. Such decision can be seen in SyntaxConsiderations and DontUseXml. Nay, this is just an exercise to see how YAML would perform in this arena.
[RichardSoderberg] This resembles very closely the RSS 3.0 specification in implementation, albeit with a YAML header and several more fields; YAML provides a clean way for transitioning to nested elements while retaining the simplicity of RFC822-style metadata headers.
--- %YAML:1.0 !echo.org,2003/^feed
title: My First Weblog
subtitle: Ain't the Interweb great?
base: http://example.com
link: /johndoe/weblog/
language: en-us
author: &j_doe
name: John Doe
url: /johndoe/
email: john.doe@example.com
created: 2003-02-05T12:29:29Z
issued: 2003-02-05T12:29:29Z
modified: 2003-02-05T12:29:29Z
contributors:
- &b_smith
name: Bob Smith
url: /bobsmith/
email: bob.smith@example.com
entries:
- id: e34
title: My First Entry
subtitle: In which a newbie learns to blog...
summary: A very boring entry; just learning how to blog here...
link: /weblog/archive/45.html
created: 2003-02-05T12:29:29Z
issued: 2003-02-05T12:29:29Z
modified: 2003-02-05T12:29:29Z
contributors:
- <<: &j_doe
role: author
- <<: &b_smith
role: graphical-artist
content:
- lang: en-us
data: >
Hello, _weblog_ world! 2 < 4!
- type: text/html
lang: en-us
data: >
<p>Hello, <em>weblog</em> world! 2 < 4!</p>
- type: image/gif
lang: en-us
data: !binary >
R0lGODlhDAAMAIQAAP//9/X17...
So, a few things I think YAML does well in this context:
-
Since YAML has built-in references, we can store all the authors and contributors at the top of the document and then use references throughout. Saves us some redundancy and kb. Looks rather clean.
-
YAML uses ISO-8601 by default, so in most languages these nodes will be loaded into the language's native timestamp. (In Ruby, we load into a Time object.)
-
Embedding HTML, text or base64 in folded blocks (a la 'content.data') truly takes care of the ugliness exhibited by CDATA.
-
YAML has base64 built-in for binary data.
YAML's toolset is far behind XML's of course, but any YAML parser could load the above. Here's a Ruby session I ran against an older version above: ('pp' is Ruby's pretty printer.)
>> require 'yaml'
=> true
>> require 'pp'
=> true
>> pp YAML::load( File.open( 'echo.yml' ) )
{"modified"=>Wed Feb 05 12:29:29 UTC 2003,
"title"=>"My First Weblog",
"issued"=>Wed Feb 05 12:29:29 UTC 2003,
"contributors"=>
[{"name"=>"Yo-Yo Dyne",
"weblog"=>"http://blog.yoyo.dyne.name/",
"homepage"=>"http://yoyo.dyne.name/"}],
"authors"=>
[{"name"=>"Bob B. Bobbington",
"weblog"=>"http://bob.blog/",
"homepage"=>"http://bob.name/"}],
"created"=>Wed Feb 05 12:29:29 UTC 2003,
"link"=>"http://bob.blog/",
"entries"=>
[{"modified"=>Wed Feb 05 12:29:29 UTC 2003,
"title"=>"My First Entry",
"issued"=>Wed Feb 05 12:29:29 UTC 2003,
"id"=>"http://bob.blog/28",
"contributors"=>
[{"name"=>"Yo-Yo Dyne",
"weblog"=>"http://blog.yoyo.dyne.name/",
"homepage"=>"http://yoyo.dyne.name/"}],
"summary"=>"A very boring entry; just learning how to blog here...",
"content"=>
[{"type"=>"text/plain",
"lang"=>"en-us",
"data"=>"Hello, _weblog_ world! 2 < 4!\n"},
{"type"=>"text/html",
"lang"=>"en-us",
"data"=>"<p>Hello, <em>weblog</em> world! 2 < 4!</p>\n"},
{"type"=>"image/gif",
"lang"=>"en-us",
"data"=>
"GIF89a\f\000\f\000\204\000\000\377\377\..."}],
"created"=>Wed Feb 05 12:29:29 UTC 2003,
"link"=>"http://bob.blog/28",
"authors"=>
[{"name"=>"Bob B. Bobbington",
"weblog"=>"http://bob.blog/",
"homepage"=>"http://bob.name/"}]}]}
Yeah, so, it's going to take a lot of self-control not to create an Echo dialect for YAML.
