Friday, August 6, 2010

Tcl and XML

TclXML is an API for parsing XML documents using the Tcl scripting language. It is also a package including a DOM implementation (TclDOM) and XSL Transformations (TclXSLT). These allow Tcl scripts to read, manipulate and write XML documents.

About TclXML

The goal of the TclXML package is to provide an API for Tcl scripts that allows "Plug-and-Play" parser implementations; ie. an application will be able to use different parser implementations without change to the application code.

The TclXML package provides a streaming, or "event-based", interface to an XML document. An application using TclXML creates a parser "object", sets a number of callback scripts and then instructs the parser to parse an XML document. The parser scans the XML document's text and as it finds certain constructs, such as the start/end of elements, character data, and so on, it invokes the appropriate callback script.

This processing model is very similar to SAX. However, TclXML does not use exactly the same method names, etc, as SAX and so it is not 100% SAX compliant. Functionally, TclXML is equivalent to SAX2.

Parser Implementations
TclXML v3.X's architecture separates the application interface from the parser implementation, in the same fashion as SAX. Currently there are two parser implementations available: tcl-parser and libxml2.

Pure-Tcl Implementation
The TclXML package provides a parser implementation written purely as a Tcl script. When no other parser is available, this one can always be used.

Having a pure-Tcl parser has some advantages, apart from the obvious advantages in not having to compile any code. This parser implementation is more configurable, can provide better error reporting and recovery and can also be modified at run-time to achieve various special features.

The Gnome libxml2 library is a C-based XML parser. It has the advantage of having high performance, as well as being able to (DTD, XSD, RNG) validate documents.

A wrapper for this library is available as part of version 3.2 of the TclXML package.

Download and Installation
TclXML v3.2 is the current release and includes the TclDOM and TclXSLT packages. This version is known to work with Tcl v8.1 and above1. Download from SourceForge:

Gzip'd tarball

Zip archive

Pull the Subversion trunk tree to get the latest-and-greatest code. There are no guarantees that the code is in any particular state (or even working at all).

Download the package in one of the forms above and unpack the downloaded file.

Detailed instructions on how to build and install TclXML may be found in the README file.

You can never have enough...

Reference Manual


Change log


TclXML: The Next Generation. Presented at the 9th Tcl Workshop, 16-19 September 2002, Vancouver Canada.

XML Support For Tcl. Tcl Workshop...

Contributions of any kind to the project are welcome.

Reporting Bugs
An important contribution you can make is to test the package and report any bugs. Use SourceForge bug tracking to report problems or request features. Please make sure you set the category to "TclXML".

We are very grateful to Invisible Worlds, who sponsored the TclXML project for most of 2000. Their contribution resulted in the development of XML Namespace support, the xmlswitch command and other features.

There are three mailing lists for the TclXML project:

tclxml-announce is a low-volume mailing list for announcements.

tclxml-devel is for discussion on the development of any of the packages within the TclXML project.

tclxml-users is for discussion on the use of any of the packages within the TclXML project.

There are instructions on SourceForge for subscribing or unsubscribing to any of these mailing lists.

You might like to view, and contribute to, the TclXML page on the Tcl/Tk Wiki. There are many other pages on the Wiki discussing XML and its use with Tcl.

Discussion also takes place on the comp.lang.tcl USENET newsgroup.

No comments: