61

I read that after years yaml will be used instead of xml. Please compare the relative advantages and disadvantages of each specification.

1
  • 6
    Where did you read that? Commented Aug 20, 2009 at 20:15

5 Answers 5

96

YAML is much less verbose. The signal-to-noise ratio is higher without all the brackets. This makes it subjectively easier to read and edit for many people. On the flip side, it's slightly (only slightly) harder to parse.

The biggest difference, though, is that XML is meant to be a markup language and YAML is really more of a data format. Representing simple, hierarchical data tends to be more gracefully done in YAML, but actual marked-up text is awkward to represent.

EDIT: I'd like to add, for reference, that YAML is essentially (though not historically) a "cleaner" version of JSON ("Javascript Object Notation") that largely eliminates the latter's perceived line noise (brackets and braces). If you can't find a suitable YAML library for a particular project, then JSON is a more widely-supported alternative with many of YAML's advantages.

5
  • 12
    I know this is old, but -1 because this doesn't even try to make a case for XML (e.g. schemas and queries which are just two perks).
    – user166390
    Commented Feb 19, 2013 at 22:34
  • 4
    I didn't post it to "make a case for XML", but to explain in general terms the purposes of the two. Anyone who knows that they want to run XQuery is going to have a much higher-level understanding of XML than a three-paragraph comment can impart, and anyone who doesn't shouldn't be picking formats based on that.
    – Thom Smith
    Commented Feb 20, 2013 at 13:39
  • 7
    Just as a little pedantry RE JSON: YAML is intended to be no such thing, it predates JSON by a number of years, and is in fact a superset of the language. This happened initially by chance, afaiu, with only a couple of minor differences, until it was noticed, at which point the specs were collaboratively brought in line with each other. Commented May 28, 2013 at 10:30
  • 4
    JSON doesn't support comments, that a big disadvantage. Commented May 7, 2017 at 5:14
  • 1
    Just about every XML vs JSON comparison I've seen mentions the lack of queries. There are now myriad ways to query JSON and other unstructured data. Even mysql does it.
    – abalter
    Commented May 13, 2018 at 22:45
33

YAML is less verbose than XML; however, YAML is meant just for data and is not technically a markup language (YAML A'int Markup Language).

2
17

A big plus for xml are the options to validate (opinions in parenthesis):

  • Schematron (extremely powerful)
  • W3C XML Schema (solid)
  • DTD (not so nice (it isn't even xml))
  • XSD (most used)

And options to query data:

  • XPath (in version 2.x even better)
  • XQuery (mostly not of interest anymore)

YAML is probably the easiest to read for humans in most cases.

JSON is quite easy to read and it is the way JavaScript stores data (correct me if wrong). I really like to use JSON when writing my own C style programming languages to parse values.

4
  • +1 People tend to forget schemas and queries when talking about JSON/YAML. I use a hybrid approach, where I surface data as JSON in my WS's, but handle XML internally. It works fairly well if adhering to some consistency rules.
    – user166390
    Commented Feb 19, 2013 at 22:33
  • Also, don't forget XSLT - while 1.0/1.1 are kind of a bore and 2.0 is not supported by Microsoft, they can very cleanly shred XML documents for further processing.
    – user166390
    Commented Feb 19, 2013 at 22:38
  • 5
    And what's worse, people tend to forget that these kinds of tools also exist for JSON and YAML (though according to a quick Google search, it seems like query tools for YAML are in infancy). Having good tools for working with a painful format can only justify using it until there are similar tools for less painful formats.
    – Andy
    Commented Aug 8, 2014 at 22:01
  • 2
    Good point but I'd like to point out there's no reason that yQuery and yPath couldn't be made at some point, and if you want to make yQuery or yPath, then the fact that they don't exist yet would tend to be a major advantage.
    – CommaToast
    Commented Nov 14, 2014 at 6:44
10

The main advantage that I see is that it is more easily human readable. I also like it a little better than XML because it has the concept of certain data structures (dictionaries and arrays) already built in.

On the flip side, the library support for parsing YAML is nowhere near that of XML, so it is harder to use it to fulfill one of the prime uses of XML. That is inter-application communication.

9

I'm not so convinced about YAML being the future. Whilst I've used it, and it WorksForMe™, I have often seem complaints about the spec. The latest of which is Why I Don't Like YAML.

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.