[Lispweb] introi and critique -- ASP, JSP, ColdFusion, PHP considered harmful
Vladimir Tsyshevsky
wowa at jet.msk.su
Thu Feb 9 03:35:50 CST 2006
Hi,
>
>Alexander Taranov <tay at jet.msk.su> writes:
>
>> xml template is actually html that could be parsed by xml-parser (we
>> use expat by James Clarck, embedded in scheme and producing tree
>> structure).
>>
...
>
>That sounds interesting. How do you *activate* the XML template with
>the dynamic data? In other words, what processing is done on the XML
>file prior to be sent over the network to the browser?
>
>--
>.....Adam Di Carlo....adam at onShore.com.....<URL:http://www.onShore.com/>
>
Alexander described the technology based on the use of
MzScheme. Working next seat to him, I use Bigloo scheme compiler
nevertheless, since it seems to me to be more appropriate for
connecting other libraries written in C/C++.
Besides, I use a bit more elaborate technique of creating dynamic HTML. In
brief, it consists of the following steps:
===================================================================================
Step 1 (optional).
The SGML template for future HTML page is created. Appropriate HTML
DTD used with the only exception: one extra element, named DATASITE
should be added to DTD. The DATASITE elements enclose parts of
templates which are to be replaced by the application.
I found the use of SGML instead of HTML or XML to be more convenient,
since SGML was specially designed for easy editing; the resulting text
is human-readable; many features such as entity replacements and
shortcuts may be used etc.
Whose who do not know SGML or dislike it, may omit this step, and
choose any way of XML creation they are accustomed to.
Step 2. SGML to XML conversion.
If the template was created in form SGML text, then out-of-the-box SX
utility from OpenSP <http://openjade.sourceforge.net> (formerly Jade)
might be used as SGML->XML converter.
Step 3. Runtime. XML -> scheme internal presentation conversion.
The XML text is parsed, and converted to internal scheme
representation of SGML tree. I use Expat as XML parser
engine. Optionally this operation might be performed in compile time
by saving the tree as binary file, to be fast-loading in runtime. Or
it may be compiled directly into the application code. Except the gain
in loading speed, this reduces the number of different software
components the runtime application depends on.
Step 4. Runtime. Tree transformation.
The template tree is processed by scheme program. All template
elements except HTML forms and DATASITE elements are copied to output
tree as is. DATASITEs processing depends on its attribute values. The
contents of DATASITEs may be either:
-- replaced by application data. It is the most obvious and commonly
used way of using templates;
-- ignored. It allows to embed all the application forms, subtemplates
into one huge template, and use only selected parts of it at time;
-- used as default contents. For instance, the application might
decide to use the contents where data is missing.
-- used recursively as subtemplate. For example, the
DATASITE for rendering HTML table might be created, which includes
three parts: table header the DATASITE for rendering of table row, and
table footer part. The table row DATASITE in turn includes table row
prefix, table cell DATASITE and table row suffix. Again, table cell
DATASITE is subtemplate itself, which includes among other elements,
the place where real application data has to be inserted.
In the real applications the recursive tree processing is performed by
special library procedure. The CGI programmer should only register the
current points of interest. For example, if the application learns
that the current page is devoted to "Site search", it registers only
the "search" DATASITE handler in a single universal template.
Step 5. Runtime. Transformed tree printed back to HTTP response
stream.
===================================================================================
It should be noticed that the template is the structured data
used for *rendering* only: it has no code inside it. The application
itself decides, how to process the template.
All the steps abovementioned are fully supported by bigloo-lib, the
set of libraries for Bigloo scheme compiler. The related modules are:
-- bigloo-node. SGML/XML tree operations including HTML printing;
-- bigloo-bexpat. Expat (XML parser) to Bigloo interface, including
recursive template transformation procedure;
-- iconv. Character set conversion support. Usually required for using expat
with character sets other than ASCII or iso-8859-1.
The bigloo-lib home is located at:
<http://bigloo-lib.sourceforge.net>
Regards,
Vladimir V. Tsychevski
senior expert
-----------------------------------------------------
Jet Infosystems
Krasnoproletarskaya 6, Tel. (+7 095) 972-1182
Moscow 103006, Russia Fax (+7 095) 972-0791
-----------------------------------------------------
Any opinions or recommendations herein are those of
the author and not of his computer.
More information about the lispweb
mailing list