Scripting and XML

Simeon Simeonov simeons at
Mon Oct 20 00:58:05 BST 1997

Disclaimer: I'm new to SGML and XML...

>So, major code reuse akin to headers in C/C++ is possible if ugly. But
>minor recycing of code is impossible for now. MSIE4 introduces a new form
>of script object handling, "scriptlets", which addresses this problem to
>some extent, but any useful script component would need to be extended
>to fit any given situation - the same problem which drives OOA&D/OOP -
>so it has yet to be seen how useful this scriptlet idea will be.

I think there is a method for code reuse that is (a) more flexible than
includes, (b) as powerful as object-based reuse (scriptlets), and (c) a lot
closer to the syntax of generalized markup. Essentially, it involves reuse
through flexible tag structures. I'd like to start with an example from my
domain of expertise--web applications. (Credit goes to Len Bullard because
the example emerged from an offline discussion about XML Scripting...)
Consider the following piece of code (ignore actual tag syntax, etc.):

<T1 A1=V1 ...>
    result = process(argument)
<T2 A2=V2 ...>

What do you do if you decide that this piece of code is useful and should be
reused? Includes won't work well, because the result of processing depends
on the value of argument. Scripts will force you to modify the code before
reuse, e.g.,

    Write("<T1 A1=V1 ...>")
    result = process(argument)
    Write("<T2 A2=V2 ...>")

Then you'll put the body of the SCRIPT tag in a procedure/function... That's
somewhat unpleasant. Code reuse shouldn't mean code re-write! What is really
needed is a mechanism which allows (a) automatic reuse of tags *and* scripts
with little code changes, and (b) safe argument passing.

The language that I am working on (CFML - the Cold Fusion Markup Language
from Allaire Corp.) uses a flexible tag-based mechanism for this. The
example code needs to modified only slightly to indicate which variables are
inputs and then needs to be placed in a separate file.

File DoSomething.cfm:
<T1 A1=V1 ...>
    result = process(Arguments.argument)
<T2 A2=V2 ...>

It can then be invoked in one of three ways:

<CF_DoSomething Argument=Value>
<CFMODULE Name="ArbitrarilyComplex.DottedNameHere.MuchLikeJava.DoSomething"
<CFMODULE Template="SomethingLikeARelativePath/DoSomething" Argument=Value>

(Please, ignore the exact details of the naming scheme.) I think that CFML's
approach is (a) significantly better than includes, (b) as powerful as
scriptlets, and (c) a lot more markup friendly. (In general, CFML is quite
tag-friendly; the language uses tags for flow-control, expression
evaluation, etc.) Also, code reuse involves less code modification than
other approaches that I know of.

Don't get me wrong. This is not the exact syntax I am recommending for XML!
I just wanted to point out one case where scripting and code reuse have been
successfully addressed with markup. There are tens of thousands of CFML
developers that strongly prefer this approach to a stew of markup and
script. In a markup language shouldn't the unit of code reuse be a tag???

I hope I have not bored you with the rather long message... If you'd like to
look at CFML and the Cold Fusion Application Server, check out


Simeon Simeonov
Language Architect
Allaire Corp.
simeons at

xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev at
Archived as:
To (un)subscribe, mailto:majordomo at the following message;
(un)subscribe xml-dev
To subscribe to the digests, mailto:majordomo at the following message;
subscribe xml-dev-digest
List coordinator, Henry Rzepa (mailto:rzepa at

More information about the Xml-dev mailing list