NAME

dom -
Create an in-memory DOM tree from XML

SYNOPSIS

dom method ?arg arg ...?

DESCRIPTION

This command provides the creation of complete DOM trees in memory. In the usual case a string containing a XML information is parsed and converted into a DOM tree. method indicates a specific subcommand.

The valid methods are:

dom parse ?options? ?data?

Parses the XML information and builds up the DOM tree in memory providing a Tcl object command to this DOM document object. Example:

dom parse $xml doc
$doc documentElement root

parses the XML in the variable xml, creates the DOM tree in memory, make a reference to the document object, visible in Tcl as a document object command, and assigns this new object name to the variable doc. When doc gets freed, the DOM tree and the associated Tcl command object (document and all node objects) are freed automatically.

set document [dom parse $xml]
set root     [$document documentElement]

parses the XML in the variable xml, creates the DOM tree in memory, make a reference to the document object, visible in Tcl as a document object command, and returns this new object name, which is then stored in document. To free the underlying DOM tree and the associative Tcl object commands (document + nodes + fragment nodes) the document object command has to be explicitly deleted by:

$document delete
or
rename $document ""

The valid options are:

-simple
If -simple is specified, a simple but fast parser is used (conforms not fully to XML recommendation). That should double parsing and DOM generation speed. UTF-8 is not generated internally with that parser. Currently this parser does not handle namespaces.
-html
If -html is specified, a fast HTML parser is used, which tries to even parse badly formed HTML into a DOM tree.
-keepEmpties
If -keepEmpties is specified, text nodes, which contain only whitespaces, will be part of the resulting DOM tree. In default case (-keepEmpties not given) those empty text nodes are removed at parsing time.
-channel <channel-ID>
If -channel <channel-ID> is specified, the input to be parsed is read from the specified channel. The input is read from the channel in "raw" (binary) mode from the channel, ignoring any encoding setting via -fconfigure of the channel.
-baseurl <baseURI>
If -baseurl <baseURI> is specified, the baseURI is used as the base URI of the document. External entities referenced in the document are resolved relative to this base URI. This base URI is also stored within the DOM tree.
-feedbackAfter <#bytes>
If -feedbackAfter <#bytes> is specified, the tcl command ::dom::domParseFeedback is evaluated after parsing every #bytes. If you use this option, you have to create a tcl proc named ::dom::domParseFeedback, otherwise you will get an error. Please notice, that the calls of ::dom::domParseFeedback are not done exactly every #bytes, but always at the first element start after every #bytes.
-externalentitycommand <script>
If -externalentitycommand <script> is specified, the specified tcl script is called to resolve any external entities of the document. The actual evaluated command consists of this option followed by three arguments: the base uri, the system identifier of the entity and the public identifier of the entity. The base uri and the public identifier may be the empty list. The script has to return a tcl list consisting of three elements. The first element of this list signals, how the external entity is returned to the processor. At the moment, the two allowed types are "string" and "channel". The second element of the list has to be the (absolute) base URI of the external entity to be parsed. The third element of the list are data, either the already read data out of the external entity as string in the case of type "string", or the name of a tcl channel, in the case of type "channel".

dom createDocument docElemName ?objVar?

Creates a new DOM document object with one element node with node name docElemName. The objVar controlls the memory handling as explained above.

dom setResultEncoding ?encodingName?

If encodingName is not given the current global result encoding is returned. Otherwise the global result encoding is set to encodingName. All character data, attribute values, etc. will then be converted from UTF-8, which is delivered from the Expat XML parser, to the given 8 bit encoding at XML/DOM parse time. Valid values for encodingName are: utf-8, ascii, cp1250, cp1251, cp1252, cp1253, cp1254, cp1255, cp1256, cp437, cp850, en, iso8859-1, iso8859-2, iso8859-3, iso8859-4, iso8859-5, iso8859-6, iso8859-7, iso8859-8, iso8859-9, koi8-r.

dom createNodeCmd (element|comment|text|cdata|pi)Node commandName

...todo...

KEYWORDS

XML, DOM, Document, node, parsing