e4Graph and XML Manipulation in Tcl

The TXML Tcl package enables a Tcl program to produce XML output from a tgraph node object, and to store XML input in a tgraph node object. Two commands are provided, txml::input and txml::output, for XML input and output operations, respectively:

package require TXML 1.0
...
set wrappertag foo
set node ...
...
set xml [txml::output $node $wrappertag]
puts $xml
==> <foo>...</foo>
and:
package require TXML
...
set string <foo>hello<bar/></foo>
set node ...
catch {tgraph::input $node -string $string} errmsg
Details

Requiring the TXML package automatically requires the TGraph package, so you do not have to require it separately.

The process of parsing XML and storing it under a given node is described here.

XML output is produced as follows:

The following table describes the commands provided by the TXML package:
  
TXML commands:
   
txml::input node -string val Parses the string val and generates new vertices and nodes in the node node. The entire string val must be consumed by the parse and the string must yield a complete parse, or an error is raised. For details on the parsing process, see the description of the e4XML library.
txml::input node -channel chan Parses input from the channel chan and creates new vertices and nodes in the node node. The channel chan must be open for reading. It is read until end of file is encountered; at that point the parse must be complete, or an error is raised.
txml::output node wrappertag ?-string? Produces XML output from the node node, wrapped in an XML tag named wrappertag. The output is returned as a string.
txml::output node wrappertag -variable varname Produces XML output from the node node, wrapped in an XML tag named wrappertag. The output is stored in the variable varname, which is created if it didn't exist before this call. The call returns the empty string.
txml::output node wrappertag -append varname Produces XML output from the node node, wrapped in an XML tag named wrappertag. The output is appended to the value of the variable varname, which is created if it didn't exist before this call. The call returns the empty string.
txml::output node wrappertag -channel chan Produces XML output from the node node, wrapped in an XML tag named wrappertag. The output is written to the channel chan, which must be opened for writing. The call returns the empty string.