News for hackers. Stuff that matters.
Re:XML Sucks by haberman on Friday January 01, 2010 @06:56AM (#1025629)
> As a standard, XML is actually pretty simple and, in my opinion, well thought out.

XML is good at text markup, but not good at data structures, which is what everyone inevitably tries to use it for. This is the basic problem.

XML by itself is a way to create tree structures of text strings. There are no data types (only strings), no schema, and no clear mapping to actual data structures in programming languages.

The evidence of XML's inadequacy for data structure serialization is that it takes a mountain of specifications (XML Schema, DOM) to address all of the needs that XML by itself does not satisfy. And even with all these specifications, there is no simple way to (for example) serialize an array of integers into XML and have them get deserialized into the same ten integers, without doing your own text manipulation.

XML has had ten years of almost no serious competition and the favor of the w3c and the web community, and all we have to show for it is an ever growing pile of specs that still fail to make data interchange easy. Also, XML is horribly inefficient.

What is the right answer? Protocol Buffers. They are 3-10x smaller, 20-100x faster to parse, they have a schema built in with real data types at the lowest level of the stack, they have both a binary and a text format, and they have a much more natural mapping onto real data structures. Compare:

  cout << "Name: " << person.name() << endl;
  cout << "E-mail: " << person.email() << endl;
with:

  cout << "Name: "
       << person.getElementsByTagName("name")->item(0)->innerText()
       << endl;
  cout << "E-mail: "
       << person.getElementsByTagName("email")->item(0)->innerText()
       << endl;
(The examples and some of the statistics I quoted come from http://code.google.com/apis/protocolbuffers/docs/overview.ht...)

There are no comments on this comment yet.