January 25th, 2005
REBOL: A better XML?
Carl has always been critical about XML. XML is verbose—that’s not news: XML, as a means for information exchange, contains a lot of redundant information. Compression of XML documents for information exchange is common.
In his recent article, Carl talks about XML, comparing it (inevitably, and for good reason too) with REBOL. Using REBOL blocks to represent semantic information makes the document readable, like XML, and at the same time is less verbose.
As an example, quoting Carl:
XML attributes don’t need a different way of representation in REBOL blocks:
Heh, I sound like REBOL is replacing XML.
In his recent article, Carl talks about XML, comparing it (inevitably, and for good reason too) with REBOL. Using REBOL blocks to represent semantic information makes the document readable, like XML, and at the same time is less verbose.
As an example, quoting Carl:
XML uses its metadata tags as grouping quotes everywhere. This extends to all levels of structure. So, to create a customer record in XML you write:As Carl mentions, in certain cases semantic may be implied too:<customer> <name>Bob Smith</name> <email>bob@example.com</email> <site>http://www.example.com/bob</site> <age>27</age> <phone>555-1212</phone> <city>Ukiah</city> </customer>The <customer> tags indicate the bounds of the customer data record.
In REBOL, there is a single mechanism for all groups of data: blocks. The above example would be:customer: [ name: "Bob Smith" email: bob@example.com site: http://www.example.com/bob</website> age: 27 phone: #555-1212 city: "Ukiah" ]Here REBOL’s block symbols [ ] are used to indicate the bounds of the customer data record. This method works for all levels of structure.
The XML situation becomes even worse when a sequential series of values needs to be expressed. Suppose the customer record above is extended to indicate products of customer interest:Now that’s something you couldn’t do with XML.<interests> <product>cpu</product> <product>memory>/product> <product>disk</product> </interests>Even if this record were 1000 products long, the same redundant tags would be applied. That's because XML uses tags as delimiters (quotes).
In REBOL, you would recognize that the products all come from the same semantic domain, so you can imply the semantics in such cases and just write:interests: [cpu memory disk]
XML attributes don’t need a different way of representation in REBOL blocks:
<search type="advanced" query="premshree" results="2">
<result>foo</result>
<result>foo</result>
</search>The REBOL equivalent of the above would be:search: [
[type "advanced" query "premshree" results 2]
["foo" "bar"]
]Ah, now comes the issue of parsing. As you can see, the second block within the search block is a hash. To be able to distinguish a hash block from an array block, some sort of convention could be adopted: having every first block within an element necessarily to be an attribute block—a hash block, that is—an empty first block in case of absence of any attributes. Umm, come to think of it, this is not really a good idea. But surely, there are ways.Heh, I sound like REBOL is replacing XML.
Posted at 10:31 pm | Link
| 21 comments | Leave a comment



