Google Groups
Subscribe to Software Outsourcing [ Hire Dedicated Group ]
Email:
Visit this group

Tuesday, August 7, 2007

YAML - Just another powerful and easy markup language

YAML is a human-readable data serialization format that takes concepts from languages such as XML, C, Python, Perl, as well as the format for electronic mail as specified by RFC 2822. YAML was first proposed by Clark Evans in 2001, who designed it together with Ingy döt Net and Oren Ben-Kiki.

YAML is a recursive acronym meaning "YAML Ain't Markup Language". Early in its development, YAML was said to mean "Yet Another Markup Language", retronymed to distinguish its purpose as data-centric, rather than document markup. However since "markup language" is frequently synonymous with data serialization, it is reasonable to consider YAML a lightweight markup language.

YAML syntax is relatively straightforward and was designed to be easily mapped to data types common to most high-level languages (lists, hashes (mappings), and scalar (single value) data.). Its familiar indented outline and lean appearance makes it especially suited for tasks where humans are likely to view or edit data structures, such as configuration files, dumping during debugging, and document headers (e.g. the headers found on most e-mails are very close to YAML in look). Its line and whitespace delimeters make it friendly to ad hoc grep/python/perl/ruby operations. YAML uses a notation based on a set of sigil characters distinct from those used in XML, making the two languages composable. A major part of its accessibility comes from eschewing the use of enclosures like quotation marks, brackets, braces, and open/close-tags which can be hard for the human eye to balance in nested hierarchies.

Data structure hierarchy is maintained by outline indentation. The following YAML document defines a hash with 7 top level keys. One of the keys, "items", contains a 2 element array (or "list"), each element of which is itself a hash with four keys. The "ship-to" hash content is copied from the "bill-to" hash's content as indicated by the anchor(&) and reference(*) labels. An optional "..." can be used at end of a file (useful for signalling an end in streamed communications without closing the pipe). Optional blank lines can be added for readability. The specific number of spaces in the indentation is unimportant as long as the hierarchy order is maintained and parallel elements have the same left justification. Multiple documents can exist in a file and are separated by "---". Notice that strings do not require enclosure in quotations.

Example:


---!myDocument
logEvent: Purchase Invoice
date: 2007-08-06
customer:
given: Dorothy
family: Gale

bill-to: &id001
street: |
123 Tornado Alley
Suite 16
city: East Westville
state: KS

ship-to: *id001

items:
- part_no: A4786
descrip: Water Bucket (Filled)
price: 1.47
quantity: 4

- part_no: E1628
descrip: High Heeled "Ruby" Slippers
price: 100.27
quantity: 1

specialDelivery: >
Follow the Yellow Brick
Road to the Emerald City.
Pay no attention to the
man behind the curtain.
...


Source