Datasheet

cool hack for defining formats that are ready to be presented while keeping some of the information that
would be available in an equivalent XML format, their rules are so flexible that they remain more diffi-
cult to process than XML formats.
Another option is to expose the same information both as XML and as (X)HTML, and that would be pos-
sible without much redundancy by the same set of common PHP functions. However, there is a second
option to avoid the duplication of code between the server and the browser: using the same language on
both sides. Of course, running PHP client side wouldn’t be very realistic. Server-side JavaScript was the
language of choice in the Netscape web servers, and it has been a popular choice for people using these
servers but has almost faded out. You may consider that unfortunate, since JavaScript isn’t worse than
other script languages around and using it both client and server side would be very coherent; however,
you won’t find many tools and frameworks to develop server-side JavaScript applications any longer.
If you want to use the same language, which is neither JavaScript nor PHP, to transform XML into
(X)HTML client and server side, you need to find a higher-level language supported in both environ-
ments. XSLT is such a language. You learn more about XSLT in Chapter 5. XSLT is a programming lan-
guage targeted to defining transformations between XML documents and transforming XML into
(X)HTML is one of its most common usages. XSLT is available both server side and client side where its
support by recent versions of Internet Explorer and Firefox is excellent. XSLT is interoperable between
environments, and it is possible to write a transformation that transforms both an XML consolidation of
the various information into a full (X)HTML document server side and the individual XML documents
into (X)HTML fragments client side.
If you have installed BuzzWatch on your station to run these examples, it’s time to install version 3.0.
Server side, the script
index.php packs all the information needed to build the whole page into a single
document with a root document element. To do so, it creates a DOM, inserts the root element, and
appends the different information:
$document = new DOMDocument();
$root = $document->createElement(“root”);
$document->appendChild($root);
appendDocument(
$document,
getAllWatches($db)
);
if ($watchRow) {
appendDocument(
$document,
getAWatch($db, $_GET[‘name’])
);
appendDocument(
$document,
get_cached_data(
getUrlQuotes($watchRow[‘symbol’]),
get_quotes_as_xml,
YAHOOFINANCE_QUOTES_LIFETIME
)
);
appendDocument(
$document,
get_cached_data(
getUrlFinancialNews($watchRow[‘symbol’]),
30
Chapter 1
04_087889 ch01.qxp 5/2/07 12:56 PM Page 30