Datasheet

and each new feature will have to be implemented both in PHP and JavaScript. Web 2.0 applications also
need to be reactive to bug reports and feature requests posted by their users, and each fix will also have
to be implemented twice.
To avoid that and minimize the maintenance costs, you have two options. The first of these options is to
perform the operations that are duplicated between the server and the browser at only one location. That
was what BuzzWatch did with its first version, where the menu bar and the panels were built only client
side in JavaScript. If it doesn’t work well to do this client side, the other option is to try to do these oper-
ations only server side. How can you do that without losing the benefits of Ajax? This is quite easy:
instead of sending XML documents to the browser, use Ajax to send (X)HTML fragments!
To implement this strategy with BuzzWatch, you would update the PHP scripts that generate the XML
for the panels and the list of watches used by the menu bar so that they send XHTML fragments instead
of XML. You could do that using the
populateXXX functions that were developed in the previous ver-
sion, and the result would be quite simple to roll out. Client side, the JavaScript would be modified to
copy the XHTML received by the XML HTTP requests straight into the document instead of reformat-
ting it as was required up to now.
Would that be a good thing? The answers that you will find to this question are often distorted by quasi-
religious wars between XML proponents and opponents. You will see in Chapter 8 that formats other
than XML can be used by Ajax applications. A popular option, JSON, is to send the text declarations of
JavaScript objects. When you receive a JSON document, your JavaScript objects are already packed in
something similar to what you get after loading an XML document in a JKL.ParseXML tree. Even if it is
simpler to get JavaScript objects straight away, the fact that libraries such as JKL.ParseXML exist means
that this doesn’t make a big difference. Compared to JSON, XML has the benefit of being totally language-
and environment-agnostic: You’ve serialized PHP arrays with SimpleXML into XML and loaded this
XML into JavaScript objects with JKL.ParseXML without any problem, and without having to see a sin-
gle angle bracket. You could have done the same between Java, C#, Python, Perl, Ruby, and so on. Doing
so with JSON would have required that each of these languages use JSON libraries to support the
JavaScript syntax for expressing literals.
XML is not only agnostic about programming languages and environment, but also about the usage that
can be done with the data. Sending the same data in (X)HTML introduces a bias toward presentation
that can be considered as bad as the bias toward JavaScript that JSON represents. It does not make any
difference for BuzzWatch as you’ve seen it up to now, but sending a list of watches as the HTML
ul
list that constitutes the Go menu represents a loss of information compared to the list of watches that
BuzzWatch uses up to now. Web 2.0 is about re-purposing information and finding new usages for exist-
ing data. Good Web 2.0 applications should not only exploit existing data to present them to their users
but also contribute by publishing information is a way that makes it easy to reuse. If you publish a list of
watches in XML, you make it easy for other Web 2.0 applications to reuse this information. If you pub-
lish the same list in XHTML, this is still possible but less straightforward.
Because (X)HTML is presentation-oriented and hides the real structure of the document, people often
present formatting XML documents in (X)HTML server side as a semantic firewall that protects your
data from being stolen. This is, of course, a very Web 1.0–ish way of seeing things!
To add semantic information in XHTML, you can also use microformats (which are covered in Chapter
10). Microformats are a way to use (X)HTML class attributes to convey the semantic information that is
lost when you transform an XML document into (X)HTML. You could define your own microformat for
the XHTML that BuzzWatch would send to the browser. However, even though microformats are a very
29
Hello Web 2.0 World
04_087889 ch01.qxp 5/2/07 12:56 PM Page 29