Scripting and XML

David Megginson ak117 at
Sun Oct 19 13:11:15 BST 1997

Simon St.Laurent writes:

 > XML at this point seems to be exceptionally well written for a
 > model in which the data is passive and gets processed by an outside
 > application - the parser/application combination.  It doesn't seem
 > like it will work very well, however, with a model that is rapidly
 > growing more popular in the HTML world: scripts included in the
 > same document as the data.  While this blending of data and
 > processor is admittedly a little unusual, it is becoming standard
 > practice more and more often.

 [Remainder omitted]

One reason that I've never tried JavaScript (other than the security
holes) is that -- as far as I can tell -- there's no way to put the
code in a separate file from the HTML page.  There are enormous
advantages to maintaining processing code separately from markup:

1) you can change processing strategies (or even the code language)
   without having to rewrite your documents;

2) the code is easier to maintain;

3) you can reuse the same code for dozens (or even thousands) of
   different documents; and

4) you can use your documents for more than one purpose.

With CSS, for example, it makes much more sense to write a single,
separate stylesheet for your whole web site than it does to embed a
separate stylesheet in each document -- in programming terms, it's the
equivalent of using a subroutine instead of writing identical code
dozens of times.  

While it is entirely legitimate to use PI's to embed code, it is nice
to keep the code as abstract as possible; for example, instead of

  <?select * from people where name='david'?>

I'd prefer something like this in the document:

  <?query dpquery?>

and then something like this in a separate source-code file:

  declare query dpquery {
    select * from people where name='david'

That way, I can find bugs more quickly, and I can change query
strategies (say, by switching from SQL to an OODB query language)
without modifying my documents.

Normally, I recommend including code within the document itself only
when the code is logically part of the document -- in literate
programming, or when the source code is included as an example.

All the best,


David Megginson                 ak117 at
Microstar Software Ltd.         dmeggins 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