Skip to main content

If you don't have an IBM ID and password, register here.

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. This profile includes the first name, last name, and display name you identified when you registered with developerWorks. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

All information submitted is secure.

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

Programming XML and Web services in TCL, Part 1 : An initial primer

Cameron Laird (Cameron@Lairds.com), Vice President, Phaseit, Inc.
Cameron is a full-time developer for independent consultancy Phaseit, Inc., based on the Texas Gulf Coast, just outside Houston. He frequently writes on Tcl and other "scripting" languages, including Python, Perl, ksh, and others less well known. In addition, he writes on GUI toolkits, data management, and testing methods. His own development projects most often are highly-reliable networked Web and industrial applications. He persists in regarding XML as a variant of SGML. He can be reached at Cameron@Lairds.com.

Summary:  Tcl and XML make good partners. Tcl boasts several strengths for standalone XML processing. Moreover, in this article XML is presented as the initial building block in a series that describes the capacity for Tcl in Web services work.

Date:  01 Apr 2001
Level:  Introductory

Comments:  

Purely XML-based tools implement 85-90% or more of an application. Programming/Scripting languages -- whether it be Tcl, Perl, Python, whatever -- are important for some aspects of building applications -- more so for B2B apps -- but XSLT and XML Schemas are used increasingly for implementing the high-level logic -- business logic, configuration data, etc. Previously, this is where Tcl was used but it is moving down in the logic chain. At least, that's the practice of Steve Ball and Zveno Pty. Ltd. of Canberra, Australia (see Resources). With this article, developerWorks kicks off a series on Tool command language (Tcl) and Web services that focuses on the status of Tcl as a language for processing XML (see Resources). This article is not a guide to learning the Tcl programming language. Please look to the Resources section for links to other articles that provide a nice explanation of the basics of Tcl.

Part of the excitement of Web services comes from the diversity of problems it solves. The benefits of Web services are available to developers working in all sorts of environments. The Tcl high-level language offers particular advantages. This first installment of the series establishes an XML-based foundation. It answers the following questions: What Tcl tools are available for working with XML? Is Tcl a fit language for XML processing?

Tcl's background

Dr. John Ousterhout invented Tcl in the late '80s. It was developed originally as an extension language for electronic design automation (EDA) tools (see Resources). Tcl almost immediately escaped from this niche and established its value in graphical user interface (GUI) construction, process management, and test automation. By the mid-'90s, it was well-established as a high-level, general-purpose development language, while continuing to be available in its original role as an embeddable "scripting" language.

By the time Ousterhout spun his own Tcl-focused company, then known as Scriptics Corporation, from Sun Microsystems at the beginning of 1998, XML was already a focus of Tcl attention. One immediately apparent reason had to do with its Unicode capabilities. Ousterhout and the other developers internal and external to Scriptics reworked Tcl to make its 8.0 release one of the first languages to handle Unicode (the standard XML encoding) properly and conveniently. For Steve Ball, the "most significant advantage" of Tcl compared to other programming languages remains internationalization: "Tcl rocks when it comes to Unicode and handling/manipulating character encodings."

Scriptics maintained its emphasis on XML throughout its brief history. In fact, when acquired in mid-2000 by Interwoven, Inc. (see Resources), the favorable price Ousterhout and other Scriptics investors received was based on his company's XML expertise, rather than any value imputed directly to Tcl. Ousterhout is now a scientist at Interwoven.

Also prominent in the development of Tcl is Marshall Rose (see Resources). Rose is the well-known author of over sixty of the Internet Engineering Task Force's (IETF) RFC standards, several books, and reference implementations of networking software having to do with electronic mail, network management, and directories (see Resources). More recently, the company he founded, Invisible Worlds (see Resources), also funded Zveno's initial development of TclXML. TclXML is the XML parser for Tcl, comparable to SAX or JAXP.


TclXML and more

More precisely, TclXML is a collection of "tools for processing and manipulating XML documents using Tcl" (see Resources). TclXML includes two parsers:

  • TclExpat, based on James Clark's (see Resources) high-performance Expat XML parser; and
  • a "native" TclXML parser, coded entirely in Tcl.

Like many other WS tools, TclXML is open source and governed by a BSD-style license traditional in the Tcl community.

Since version 2.0theta last year, TclXML has supported XML Namespaces in a convenient abstraction away from XML syntax details. Tcl has its own namespace constructs, so it has been natural for Ball to attach XML Namespaces to Tcl namespaces. As he explains,

Then any reference to an element within that namespace is translated to an evaluation of a Tcl procedure with the same local-name in the Tcl Namespace.

Ball uses this technique in Zwik, his company's internal content managment system.

Layered over TclXML is TclDOM, a Tcl language binding to the Document Object Model (DOM). The natural visual representation of DOM marries well with the GUI capabilities of the Tk graphical extension to Tcl. TclDOM includes two Tk-coded megawidgets, DOMText, and TreeDOM that respect DOM events and expose XML Namespaces handily.

Standard Tcl is simply procedural, although a dozen different object-oriented extensions or supersets of Tcl are more or less in active use. According to the World Wide Web Consortium (W3C [see Resources]), "DOM API is heavily slanted towards O-O languages." And Advanced Rotorcraft Technology, Inc., Software Engineer Joe English reminds us that "it's to Steve's (Ball's) great credit that he was able to come up with an interpretation of this API that actually works well with Tcl."

Ball also introduced XPath support in TclDOM in the winter of 2001. XPath integrates XML content in a Web addressing scheme. The benefits to Tcl programmers include:

  • XPath-based navigation through DOM trees;
  • XPath-expressed construction of DOM trees; and
  • a TclXML package called cgi2dom which presents Web forms as DOM trees. Zveno uses cgi2dom in production systems to render form submissions into XML documents. XSLT applications process the form templates and their results with tiny Tcl evaluations connecting the inputs and outputs through a Web server.

Showcases for TclXML

TclXML users have applied the project in several different ways. Ousterhout's company concentrated on XML as a common language in business-to-business developments that often worked from legacy data. Zveno's clients, many of them in government or government suppliers, generally call on it for help publishing and managing content. Ball is enthusiastic about a "functional" approach that uses XSL and other XML tools to express the bulk of a transformation and "glues" the endpoints to such externals as a filesystem with Tcl. He explains it this way:

XSL can't (and isn't designed to) do everything. So what kinds of problems cannot be solved using XSLT? Usually where an interface needs to be built to an external system; the filesystem is a good example. I used to simply use a Tcl script to generate HTML, but the HTML index page must be styled differently for ourselves and our clients. Now, we use a very small Tcl script to generate a file called manifest.xml. This file simply lists the files and subdirectories in a filesystem directory in XML format. We then use an XSLT stylesheet to create the index page. Our clients just slot in a different stylesheet. The manifest file becomes useful for other purposes as well, like creating sitemaps, overviews, [and so on] of the database content.

Most TclXML contributors and consumers appear to be experienced engineers who recognize that several languages, including Java, Python, and Tcl, have roughly comparable algorithmic capabilities. They favor Tcl for the traditional strengths Ball summarizes as "simplicity, easy integration, and breadth of applicability." Its qualities include

  • top-flight encoding management, including Unicode;
  • succinct expression of high-level "piping" of data from one domain to another;
  • integrated graphics in Tk; and
  • expressive, consistent retrieval of legacy data both through database interfaces and Expect. Expect is a unique Tcl extension which automates interaction with difficult interfaces; think of it as a general-purpose "screen-scraper" for legacy programs (see Resources).

At the other end of the seniority range is third-year Newcastle University student Sam Aaron with his dissertation project on XML-encoded autonomous agents (see Resources). He selected Tcl as his implementation language despite the solid year of background he had in Java and its popularity in agent research. Tcl's simplicity and the robustness of TclXML contributed to his completion of half of his planned agent authoring tool in the first week of his exposure to the language. For him, "It's like a breath of fresh air after C++ and Java!"

A more polished showcase for Tcl advantages is e4graph. e4graph is Jacob Levy's general-purpose library for reliable, strikingly efficient, and portable persistent storage for graph-like data. e4graph's XML binding gives an instant-on, highly compact, remarkably portable format for persistent XML documents (see Resources). Ball hopes at some point to connect a TclDOM-e4graph interface to his company's "waX Me Lyrical" Tcl-coded XML editor for "instantly-opened pre-parsed documents" (see Resources).


Summary

Ball has it right: "XML is the future." Implementation language for procedural operations is secondary. Within that framework, though, Tcl is a fine vehicle for many applications. Tcl boasts such highlights as e4graph and several mission-critical systems already successfully moved to production.

Tcl certainly doesn't have the scale of talent that appears to be currently funded for such languages as Java, Visual Basic, and Python. Several good TclXML enhancements are dormant, waiting for a volunteer with time or a sponsor with money. Progress in specific areas continues, though. Ball and convention staffers expect good attendance at the four tutorials he'll present at this summer's Open Source Convention (see Resources). Future installments in this series will examine Tcl capabilities and applications with SOAP, WSDL, and UDDI.


Resources

  • Zveno Pty Ltd. is Steve Ball's Australian development and training house. It specializes in XML-based applications.

  • Tcl is a popular high-level language for a variety of development applications.

  • Find out about John Ousterhout, the creator of TCL.

  • Interwoven, Inc. is a leading provider in the area of XML-based content management, and John Ousterhout's employer.

  • Invisible Worlds is developing protocols designed to succeed HTTP. Its founder and CTO is Marshall Rose.

  • Internet Engineering Task Force (IETF): the IETF issues many of the fundamental Internet standards.

  • Visit TclXML home at SourceForge.

  • James Clark's Home Page: Clark has authored several very widely-used reference pieces of software having to do with SGML and XML processes.

  • W3C: the World-Wide Web Consortium is, along with the IETF, the principle publisher of Internet standards.

  • Visit the home page of Joe English, the principal author of the C-coded version of TclDOM.

  • Pick up free software at e4graph home. Software that represents and stores graphs.

  • MetaKit home page: MetaKit is the persistence library e4graph leverages.

  • The O'Reilly Open Source Convention is offering an XML track and several XML tutorials are available this summer.

  • "waX Me Lyrical" (also WAX), the XML editor home page. Zveno originally wrote WAX.

About the author

Cameron is a full-time developer for independent consultancy Phaseit, Inc., based on the Texas Gulf Coast, just outside Houston. He frequently writes on Tcl and other "scripting" languages, including Python, Perl, ksh, and others less well known. In addition, he writes on GUI toolkits, data management, and testing methods. His own development projects most often are highly-reliable networked Web and industrial applications. He persists in regarding XML as a variant of SGML. He can be reached at Cameron@Lairds.com.

Report abuse help

Report abuse

Thank you. This entry has been flagged for moderator attention.


Report abuse help

Report abuse

Report abuse submission failed. Please try again later.


developerWorks: Sign in

If you don't have an IBM ID and password, register here.


Forgot your IBM ID?


Forgot your password?
Change your password


By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. This profile includes the first name, last name, and display name you identified when you registered with developerWorks. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

Choose your display name

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

(Must be between 3 – 31 characters.)


By clicking Submit, you agree to the developerWorks terms of use.

 


Rate this article

Comments

Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=SOA and web services, XML
ArticleID=11523
ArticleTitle=Programming XML and Web services in TCL, Part 1 : An initial primer
publish-date=04012001
author1-email=Cameron@Lairds.com
author1-email-cc=

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

For articles in technology zones (such as Java technology, Linux, Open source, XML), Popular tags shows the top tags for all technology zones. For articles in product zones (such as Info Mgmt, Rational, WebSphere), Popular tags shows the top tags for just that product zone.

For articles in technology zones (such as Java technology, Linux, Open source, XML), My tags shows your tags for all technology zones. For articles in product zones (such as Info Mgmt, Rational, WebSphere), My tags shows your tags for just that product zone.

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).