1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>TclDOM</title><meta name="generator" content="DocBook XSL Stylesheets V1.60.1"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="refentry"><h1 class="title"><a name="id222773">TclDOM</a></h1><h2>Contents</h2><ul><li><a href="#synopsis">Synopsis</a></li><li><a href="#Description">Description</a></li><li><a href="#Packages-and-Namespaces">Packages and Namespaces</a></li><li><a href="#Tokens">Tokens</a></li><li><a href="#DOM-Interfaces">DOM Interfaces</a></li><li><a href="#Convenience-Commands-and-Methods">Convenience Commands and Methods</a></li><li><a href="#Commands">Commands</a><ul><li><a href="#Commands-::dom::DOMImplementation">::dom::DOMImplementation</a><ul><li><a href="#Commands-::dom::DOMImplementation-Command-Options">Command Options</a></li></ul></li><li><a href="#Commands-::dom::document">::dom::document</a></li><li><a href="#Commands-dom::node">dom::node</a></li><li><a href="#Commands-dom::element">dom::element</a></li><li><a href="#Commands-dom::processinginstruction">dom::processinginstruction</a></li><li><a href="#Commands-dom::event">dom::event</a></li></ul></li><li><a href="#Implementations">Implementations</a><ul><li><a href="#Implementations-Tcl-Implementation">Tcl Implementation</a></li><li><a href="#Implementations-libxml2-Implementation">libxml2 Implementation</a><ul><li><a href="#Implementations-libxml2-Implementation-Notes">Notes</a></li></ul></li></ul></li></ul><div class="refnamediv"><h2>Name</h2><p>::dom::DOMImplementation, ::dom::create, ::dom::parse, ::dom::serialize, ::dom::document, ::dom::node, ::dom::element, ::dom::event, ::dom::selectNode &#8212; Tcl language binding for the W3C Document Object Model</p></div><div class="refsynopsisdiv"><a name="synopsis"></a><h2>Synopsis</h2><div class="tclcmdsynopsis" id="id269266"><a name="id269266"></a>
2      <span class="command" id="id269269"><a name="package_require_dom"></a><tt class="command">package require dom</tt> </span>
3    </div><br><span class="tclpkgsynopsis"><pre>package require dom ?2.5?</pre></span><div class="tclcmdsynopsis" id="id268780"><a name="id268780"></a>
4      <span class="command" id="id268783"><a name="__dom__DOMImplementation"></a><tt class="command">::dom::DOMImplementation</tt> </span>
5      <i class="replaceable"><tt>method</tt></i>
6      ?args...?
7    </div><div class="tclcmdsynopsis" id="id268821"><a name="id268821"></a>
8      <span class="command" id="id268824"><a name="__dom__create"></a><tt class="command">::dom::create</tt> </span>
9      <i class="replaceable"><tt>element</tt></i>
10    </div><div class="tclcmdsynopsis" id="id268845"><a name="id268845"></a>
11      <span class="command" id="id268848"><a name="__dom__parse"></a><tt class="command">::dom::parse</tt> </span>
12      <i class="replaceable"><tt>xml</tt></i>
13      ?option value...?
14    </div><div class="tclcmdsynopsis" id="id268895"><a name="id268895"></a>
15      <span class="command" id="id268898"><a name="__dom__serialize"></a><tt class="command">::dom::serialize</tt> </span>
16      <i class="replaceable"><tt>token</tt></i>
17      ?option value...?
18    </div><div class="tclcmdsynopsis" id="id268945"><a name="id268945"></a>
19      <span class="command" id="id268948"><a name="__dom__document"></a><tt class="command">::dom::document</tt> </span>
20      <i class="replaceable"><tt>method</tt></i>
21       <i class="replaceable"><tt>token</tt></i>
22      ?args...?
23    </div><div class="tclcmdsynopsis" id="id268999"><a name="id268999"></a>
24      <span class="command" id="id269002"><a name="__dom__node"></a><tt class="command">::dom::node</tt> </span>
25      <i class="replaceable"><tt>method</tt></i>
26       <i class="replaceable"><tt>token</tt></i>
27      ?args...?
28    </div><div class="tclcmdsynopsis" id="id269052"><a name="id269052"></a>
29      <span class="command" id="id269055"><a name="__dom__element"></a><tt class="command">::dom::element</tt> </span>
30      <i class="replaceable"><tt>method</tt></i>
31       <i class="replaceable"><tt>token</tt></i>
32      ?args...?
33    </div><div class="tclcmdsynopsis" id="id269871"><a name="id269871"></a>
34      <span class="command" id="id269874"><a name="__dom__event"></a><tt class="command">::dom::event</tt> </span>
35      <i class="replaceable"><tt>method</tt></i>
36       <i class="replaceable"><tt>token</tt></i>
37      ?args...?
38    </div><div class="tclcmdsynopsis" id="id269494"><a name="id269494"></a>
39      <span class="command" id="id269497"><a name="__dom__selectNode"></a><tt class="command">::dom::selectNode</tt> </span>
40      <i class="replaceable"><tt>token</tt></i>
41       <i class="replaceable"><tt>xpath</tt></i>
42      ?option value...?
43    </div><h3>Tcl Namespace Usage</h3>
44      <br><tt class="tclnamespace">::dom</tt>
45      <br><tt class="tclnamespace">::dom::tcl</tt>
46      <br><tt class="tclnamespace">::dom::libxml2</tt>
47    <p></p></div><div class="refsect1" lang="en"><h2>Description</h2><p>TclDOM is a Tcl language binding for the <a href="http://www.w3c.org/DOM/" target="_top">W3C Document Object Model</a> (DOM).  DOM provides a view of a XML (or HTML) document as a tree structure.  Currently, TclDOM only supports XML documents.</p><p>The package implements most of the DOM Level 1 interfaces and also some Level 2 and Level 3 interfaces.  There are also a number of non-standard commands and methods provided for the convenience of application developers (these are documented).</p><p>The DOM specification should be read in conjunction with this reference manual, as it explains the meaning and purpose of the various interfaces.  This manual is not a tutorial on how to use the DOM.</p><p>TclDOM also provides several implementations of the API, with a layered architecture.  A generic layer provides a stable API to the application, and specific implementations may register themselves.  Currently, three implementations exists: a pure-Tcl implementation, a C implementation (based on TclDOMPro) and another C implementation based on the Gnome libxml2 &amp; gdome2 libraries.</p></div><div class="refsect1" lang="en"><h2>Packages and Namespaces</h2><p>The TclDOM generic layer defines the <tt class="tclpackage">dom</tt> package and also a Tcl namespace using that name.  The generic layer also uses the package name <tt class="tclpackage">dom::generic</tt>.</p><p>Implementations define their own package name and Tcl namespace within the generic layer:</p><div class="variablelist"><dl><dt><span class="term">Tcl implementation</span></dt><dd><p>Package <tt class="tclpackage">dom::tcl</tt>, Tcl namespace <tt class="tclnamespace">::dom::tcl</tt>.</p></dd><dt><span class="term">TclDOMPro</span></dt><dd><p>Package <tt class="tclpackage">dom::c</tt>, Tcl namespace <tt class="tclnamespace">::dom::c</tt>.</p></dd><dt><span class="term">libxml2</span></dt><dd><p>Package <tt class="tclpackage">dom::libxml2</tt>, Tcl namespace <tt class="tclnamespace">::dom::libxml2</tt>.</p></dd></dl></div></div><div class="refsect1" lang="en"><h2>Tokens</h2><p>The TclDOM API uses <span class="emphasis"><em>tokens</em></span> as identifiers for nodes within the document tree.  This technique has been used to allow alternate implementations of TclDOM to be efficient, while retaining compatibility with the pure-Tcl implementation.</p><p>The format of the token itself as well as the data structure referred to by the token are <span class="emphasis"><em>not</em></span> public and an application should not rely on these.  Instead, an application should use the accessor methods provided by the API.</p></div><div class="refsect1" lang="en"><h2>DOM Interfaces</h2><p>Each <span class="emphasis"><em>Interface</em></span> in the DOM specification is implemented with a Tcl command in the <tt class="tclnamespace">dom</tt> namespace.  A few interfaces have not been mapped to Tcl commands because Tcl already provides the required functionality, for example the <tt class="classname">CharacterData</tt> interface.</p><p><span class="emphasis"><em>method</em></span>s for interfaces are methods (subcommands) of the corresponding Tcl command.</p><p>Each <span class="emphasis"><em>attribute</em></span> of an interface is a configuration option for an object in the document tree.</p></div><div class="refsect1" lang="en"><h2>Convenience Commands and Methods</h2><p>DOM doesn't always provide an interface, method or attribute for every function required.  For example, until DOM Level 3 for was no standard for creating, parsing and serializing a document.  Sometimes using the standard DOM interface is awkward.  TclDOM provides a number of non-standard features to overcome these problems.</p><p>A major convenience is that each method of the <tt class="classname">DOMImplementation</tt> interface is also defined as a command.  For example, rather than using <a href="#dom__DOMImplementation_create"><b class="tclcommand">dom::DOMImplementation create</b></a> to create a new document, the shorter command <a href="#dom__create"><b class="tclcommand">dom::create</b></a> may be used.</p><p>Implementations may also provide direct access to specific features.  Refer to the documentation for a DOM implementation.</p></div><div class="refsect1" lang="en"><h2>Commands</h2><div class="refsect2" lang="en"><h3><a href="#__dom__DOMImplementation"><b class="tclcommand">::dom::DOMImplementation</b></a></h3><p>The <a href="#__dom__DOMImplementation"><b class="tclcommand">::dom::DOMImplementation</b></a> command implements the <tt class="classname">DOMImplementation</tt> DOM interface.  It is used to provide implementation-specific features not explicitly defined in the DOM specification.</p><div class="refsect3" lang="en"><h4>Command Options</h4><p>The following command options may be used.  These are also available as commands.</p><div class="variablelist"><dl><dt><span class="term"><tt class="methodname">hasFeature</tt></span></dt><dd><div class="tclcmdsynopsis" id="id307525"><a name="id307525"></a>
48	        hasFeature
49	         <i class="replaceable"><tt>feature</tt></i>
50	      </div><p>Provides a test for existence of a feature.  Returns <tt class="literal">1</tt> if a feature is implemented, <tt class="literal">0</tt> otherwise.  Uses the default DOM implementation.</p></dd><dt><span class="term"><tt class="methodname">create</tt></span></dt><dd><div class="tclcmdsynopsis" id="id269950"><a name="id269950"></a>
51	        create
52	         <i class="replaceable"><tt>type</tt></i>
53	      </div><p>Creates the root node of a new DOM document, using the default DOM implementation.  The document element type may be specified as an argument, in which case that element is created.  The return value is a token referring to the root node of the newly created document.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>Non-standard method.  DOM Level 2 introduced the <tt class="methodname">createDocument</tt> method.</p></div></dd><dt><span class="term"><tt class="methodname">createDocument</tt></span></dt><dd><div class="tclcmdsynopsis" id="id270020"><a name="id270020"></a>
54	        createDocument
55	         <i class="replaceable"><tt>nsURI</tt></i>
56	         <i class="replaceable"><tt>type</tt></i>
57	         <i class="replaceable"><tt>doctype</tt></i>
58	      </div><p>Creates the root node of a new DOM document, using the default DOM implementation.  The document element namespace URI and local-name (element type) may be specified as an argument, in which case that element is created.  If the document type is given then the newly created document is configured to use that document type.  The return value is a token referring to the root node of the newly created document.</p></dd><dt><span class="term"><tt class="methodname">createDocumentType</tt></span></dt><dd><div class="tclcmdsynopsis" id="id270098"><a name="id270098"></a>
59	        createDocumentType
60	         <i class="replaceable"><tt>token</tt></i>
61	         <i class="replaceable"><tt>name</tt></i>
62	         <i class="replaceable"><tt>publicid</tt></i>
63	         <i class="replaceable"><tt>systemid</tt></i>
64	         <i class="replaceable"><tt>internaldtd</tt></i>
65	      </div><p>Creates a Document Type Declaration, using the default DOM implementation.  The return value is a token for the newly created document type declaration.</p></dd><dt><span class="term"><tt class="methodname">createNode</tt></span></dt><dd><div class="tclcmdsynopsis" id="id317936"><a name="id317936"></a>
66	        createNode
67	         <i class="replaceable"><tt>token</tt></i>
68	         <i class="replaceable"><tt>xpath</tt></i>
69	      </div><p>May create a node in the document.  <tt class="option"><i class="replaceable"><tt>token</tt></i></tt> specifies a context for the XPath expression given by <tt class="option"><i class="replaceable"><tt>xpath</tt></i></tt>.  The expression must resolve to a node.  If the node exists then no further action is taken.  Otherwise the node is created.  The token of the matched or newly created node is returned.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>Non-standard method.</p></div></dd><dt><span class="term"><tt class="methodname">destroy</tt></span></dt><dd><div class="tclcmdsynopsis" id="id318299"><a name="id318299"></a>
70	        destroy
71	         <i class="replaceable"><tt>token</tt></i>
72	      </div><p>This method frees all data structures associated with a DOM node.  The <tt class="option"><i class="replaceable"><tt>token</tt></i></tt> argument must refer to a valid token for any node in the document tree.  The node is removed from the tree before it is destroyed.  If the node has children, they will also be destroyed.</p></dd><dt><span class="term"><tt class="methodname">isNode</tt></span></dt><dd><div class="tclcmdsynopsis" id="id318362"><a name="id318362"></a>
73	        isNode
74	         <i class="replaceable"><tt>token</tt></i>
75	      </div><p>Tests whether the given token is a valid token for some DOM node in the default DOM implementation.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>Non-standard method.</p></div></dd><dt><span class="term"><tt class="methodname">parse</tt></span></dt><dd><div class="tclcmdsynopsis" id="id318420"><a name="id318420"></a>
76	        parse
77	         <i class="replaceable"><tt>xml</tt></i>
78	        ?<i class="replaceable"><tt>option</tt></i> <i class="replaceable"><tt>value</tt></i>?
79	      </div><p>This method parses XML formatted text given by the <tt class="option"><i class="replaceable"><tt>xml</tt></i></tt> argument and constructs a DOM tree for the document.  The return result is the token of the root node of the newly created document.</p><p>This method requires an event-based XML parser to be loaded to perform the parsing operation.  The <tt class="tclpackage">dom</tt> package itself does not include an XML parser.  Support for the use of <a href="http://tclxml.sourceforge.net/" target="_top">TclXML</a> is provided.  Any other Tcl event-based XML parser
80implementing the TclXML API may also be used.  The <tt class="option">-parser</tt> may be used to specify which XML parser to use.</p><p>In some circumstances, a DOM implementation may parse the XML document directly, for example libxml2.  In this case, it may not be possible to interpose on the parsing operation.</p><p>Valid configuration options are:</p><div class="variablelist"><dl><dt><span class="term">[-parser]  [[[{}] |  [expat] |  [tcl]]]</span></dt><dd><p>This option specifies which XML parser to use to parse the XML data.  If an empty string is given then the default behaviour described above is used.  The value <tt class="option">expat</tt> specifies that the Expat parser must be used.  The value <tt class="option">tcl</tt> specifies that the Tcl-only parser must be used.  If an explicit value is given and that parser cannot be loaded then the command will fail, despite the fact that another parser may be available.</p></dd><dt><span class="term">[-progresscommand]  [<i class="replaceable"><tt>script</tt></i>]</span></dt><dd><p>This option specifies a Tcl command to be invoked from time to time while the DOM tree is being constructed.  The script will be invoked after a certain number of element start tags have been processed, given by the <tt class="option">-chunksize</tt> option.</p></dd><dt><span class="term">[-chunksize]  [<i class="replaceable"><tt>integer</tt></i>]</span></dt><dd><p>This option specifies how many element start tags to process before invoking the script given by the <tt class="option">-progresscommand</tt> option.</p></dd></dl></div></dd><dt><span class="term"><tt class="methodname">selectNode</tt></span></dt><dd><div class="tclcmdsynopsis" id="id318737"><a name="id318737"></a>
81	        selectNode
82	         <i class="replaceable"><tt>token</tt></i>
83	         <i class="replaceable"><tt>xpath</tt></i>
84		?option value...?
85	      </div><p>Resolves the XPath location path given by <tt class="option"><i class="replaceable"><tt>xpath</tt></i></tt>.  <tt class="option"><i class="replaceable"><tt>token</tt></i></tt> is the initial context for the location path.  Returns the resulting nodeset as a Tcl list.</p><p>The following options may be specified:</p><div class="variablelist"><dl><dt><span class="term"><tt class="option">-namespaces</tt></span></dt><dd><p>The value for this option is a list of prefix-URI pairs.  Each of these pairs defines an XML Namespace and its prefix for the purposes of evaluating the XPath expression.  The document itself may use a different prefix for the same XML Namespace.</p><p>This option may be repeated, in which case the lists of namespace pairs are merged and all of the XML Namespaces registered.</p></dd></dl></div><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>Non-standard method.</p></div></dd><dt><span class="term"><tt class="methodname">serialize</tt></span></dt><dd><div class="tclcmdsynopsis" id="id318878"><a name="id318878"></a>
86	        serialize
87		 <i class="replaceable"><tt>token</tt></i>
88	        ?<i class="replaceable"><tt>option</tt></i> <i class="replaceable"><tt>value</tt></i>?
89	      </div><p>This method returns the XML formatted text corresponding to the node given by <tt class="option">token</tt>.  The text is guaranteed to be a well-formed XML document, unless the <tt class="option">-method</tt> option specifies a non-XML output method.</p><p>Valid configuration options are:</p><div class="variablelist"><dl><dt><span class="term">[-newline]  [<i class="replaceable"><tt>elementlist</tt></i>]</span></dt><dd><p>This option specifies a list of element types for which newline characters will be added before and after the start and end tags for those elements upon serialization.</p><p>White space is significant in XML, so the <tt class="tclpackage">dom</tt> package never adds extra white spacefor purposes of &quot;pretty-printing&quot; the XML source document.  On some platforms, such as VMS, this can actually cause serious problems due to line length limitations.  This option provides the convenience of adding newlines to certain nominated element types for formatting the source into lines.</p><p>Examples:</p><p>Suppose the following DOM document is constructed:</p><div class="informalexample"><pre class="programlisting">
90set doc [::dom::DOMImplementation create]
91set top [::dom::document createElement $doc Root]
92set node [::dom::document createElement $top First]
93::dom::document createElement $node Second
94::dom::document createElement $top First
95</pre></div><p>Without the <tt class="option">-newline</tt> option the serialized document would be:</p><div class="informalexample"><pre class="programlisting">
96::dom::DOMImplementation serialize $doc
97<tt class="computeroutput">
98&lt;?xml version=&quot;1.0&quot;?&gt;
99&lt;!DOCTYPE Root&gt;
100&lt;Root&gt;&lt;First&gt;&lt;Second/&gt;&lt;/First&gt;&lt;First/&gt;&lt;/Root&gt;
101
102</tt>
103</pre></div><p>With the <tt class="option">-newline</tt> option the serialized document would be:</p><div class="informalexample"><pre class="programlisting">
104::dom::DOMImplementation serialize $doc -newline First
105<tt class="computeroutput">
106&lt;?xml version=&quot;1.0&quot;?&gt;
107&lt;!DOCTYPE Root&gt;
108&lt;Root&gt;
109&lt;First&gt;
110&lt;Second/&gt;
111&lt;/First&gt;
112&lt;First/&gt;
113&lt;/Root&gt;
114
115</tt>
116</pre></div></dd></dl></div></dd><dt><span class="term"><tt class="methodname">trim</tt></span></dt><dd><div class="tclcmdsynopsis" id="id319140"><a name="id319140"></a>
117		trim
118		 <i class="replaceable"><tt>token</tt></i>
119	      </div><p>This method removes any node containing only white space from the document tree of the node given by <tt class="option"><i class="replaceable"><tt>token</tt></i></tt>.</p></dd></dl></div></div></div><div class="refsect2" lang="en"><h3><a href="#__dom__document"><b class="tclcommand">::dom::document</b></a></h3><p>This command implements the Document interface in the DOM specification.  The most important aspect of this command are its factory methods for creating nodes.</p><p>The methods accepted by this command are as follows:</p><div class="variablelist"><dl><dt><span class="term"><tt class="methodname">cget</tt></span></dt><dd><div class="tclcmdsynopsis" id="id319228"><a name="id319228"></a>
120	      <tt class="methodname">cget</tt>
121	      <i class="replaceable"><tt>token</tt></i>
122	       -option
123	    </div><p>This method returns the value of the given configuration option.</p></dd><dt><span class="term"><tt class="methodname">configure</tt></span></dt><dd><div class="tclcmdsynopsis" id="id319281"><a name="id319281"></a>
124	      <tt class="methodname">configure</tt>
125	      <i class="replaceable"><tt>token</tt></i>
126	      ?<i class="replaceable"><tt>option</tt></i> <i class="replaceable"><tt>value</tt></i>...?
127	    </div><p>This method sets the value of the given configuration options.</p><p>Valid configuration options are:</p><div class="variablelist"><dl><dt><span class="term">[-doctype]</span></dt><dd><p>Specifies the token of the Document Type Declaration node.</p><p>This is a read-only option.  Use the factory method to create a Document Type Declaration node.</p></dd><dt><span class="term">[-implementation]</span></dt><dd><p>Specifies the token of the document's implementation.</p><p>This is a read-only option.</p></dd><dt><span class="term">[-documentElement]</span></dt><dd><p>Specifies the token of the document's document element node.  A document node may only have one document element, but may have other types of children (such as comments).</p><p>This is a read-only option.  Use the factory method to create the document element node.</p></dd></dl></div></dd><dt><span class="term"><tt class="methodname">createElement</tt></span></dt><dd><div class="tclcmdsynopsis" id="id319466"><a name="id319466"></a>
128	      <tt class="methodname">createElement</tt>
129	      <i class="replaceable"><tt>token</tt></i>
130	       <i class="replaceable"><tt>type</tt></i>
131	    </div><p>This method creates an element node as a child of the given node specified by <tt class="option"><i class="replaceable"><tt>token</tt></i></tt>.  <tt class="option"><i class="replaceable"><tt>token</tt></i></tt> must be a node of type element, document or documentFragment.  The new, child element is added as the last child of <tt class="option"><i class="replaceable"><tt>token</tt></i></tt>'s list of children.  The new element's type is given by the <tt class="option"><i class="replaceable"><tt>type</tt></i></tt> argument.  The new element is created with an empty attribute list.</p></dd><dt><span class="term"><tt class="methodname">createElementNS</tt></span></dt><dd><div class="tclcmdsynopsis" id="id319550"><a name="id319550"></a>
132	      <tt class="methodname">createElementNS</tt>
133	      <i class="replaceable"><tt>token</tt></i>
134	       <i class="replaceable"><tt>nsuri</tt></i>
135	       <i class="replaceable"><tt>qualname</tt></i>
136	    </div><p>This method creates an element node in an XML Namespace as a child of the given node specified by <tt class="option"><i class="replaceable"><tt>token</tt></i></tt>.  <tt class="option"><i class="replaceable"><tt>token</tt></i></tt> must be a node of type element, document or documentFragment.  The new, child element is added as the last child of <tt class="option"><i class="replaceable"><tt>token</tt></i></tt>'s list of children.  The new element is created in the XML Namespace given by the namespace URI <tt class="option"><i class="replaceable"><tt>nsuri</tt></i></tt>.  The new element's qualifed name (QName) is given by the <tt class="option"><i class="replaceable"><tt>qualname</tt></i></tt> argument.  Qualified names have the form <tt class="literal">prefix:local-part</tt>.  The new element is created with an empty attribute list.</p></dd><dt><span class="term"><tt class="methodname">createDocumentFragment</tt></span></dt><dd><div class="tclcmdsynopsis" id="id319662"><a name="id319662"></a>
137	      <tt class="methodname">createDocumentFragment</tt>
138	      <i class="replaceable"><tt>token</tt></i>
139	    </div><p>This method creates a documentFragment node as a child of the given node specified by <tt class="option"><i class="replaceable"><tt>token</tt></i></tt>.  <tt class="option"><i class="replaceable"><tt>token</tt></i></tt> must be a node of type element, document or documentFragment.</p></dd><dt><span class="term"><tt class="methodname">createTextNode</tt></span></dt><dd><div class="tclcmdsynopsis" id="id319719"><a name="id319719"></a>
140	      <tt class="methodname">createTextNode</tt>
141	      <i class="replaceable"><tt>token</tt></i>
142	       <i class="replaceable"><tt>text</tt></i>
143	    </div><p>This method creates a textNode node as a child of the given node specified by <tt class="option"><i class="replaceable"><tt>token</tt></i></tt>.  <tt class="option"><i class="replaceable"><tt>token</tt></i></tt> must be a node of type element, document or documentFragment.  The new, child textNode is added as the last child of <tt class="option"><i class="replaceable"><tt>token</tt></i></tt>'s list of children.  The new textNode is created with its value set to <tt class="option"><i class="replaceable"><tt>text</tt></i></tt>.</p></dd><dt><span class="term"><tt class="methodname">createComment</tt></span></dt><dd><div class="tclcmdsynopsis" id="id319802"><a name="id319802"></a>
144	      <tt class="methodname">createComment</tt>
145	      <i class="replaceable"><tt>token</tt></i>
146	       <i class="replaceable"><tt>data</tt></i>
147	    </div><p>This method creates a comment node as a child of the given node specified by <tt class="option"><i class="replaceable"><tt>token</tt></i></tt>.  <tt class="option"><i class="replaceable"><tt>token</tt></i></tt> must be a node of type element, document or documentFragment.  The new, child comment is added as the last child of <tt class="option"><i class="replaceable"><tt>token</tt></i></tt>'s list of children.  The new comment is created with its value set to <tt class="option"><i class="replaceable"><tt>data</tt></i></tt>.</p></dd><dt><span class="term"><tt class="methodname">createCDATASection</tt></span></dt><dd><div class="tclcmdsynopsis" id="id319884"><a name="id319884"></a>
148	      <tt class="methodname">createCDATASection</tt>
149	      <i class="replaceable"><tt>token</tt></i>
150	       <i class="replaceable"><tt>text</tt></i>
151	    </div><p>TclDOM does not distinguish between textNodes and CDATASection nodes.  Accordingly, this method creates a textNode node as a child of the given node specified by <tt class="option"><i class="replaceable"><tt>token</tt></i></tt>.  <tt class="option"><i class="replaceable"><tt>token</tt></i></tt> must be a node of type element, document or documentFragment.  The new, child textNode is added as the last child of <tt class="option"><i class="replaceable"><tt>token</tt></i></tt>'s list of children.  The new node is created with its value set to <tt class="option"><i class="replaceable"><tt>text</tt></i></tt> and has the attribute <tt class="option">-cdatasection</tt> set to the value <tt class="literal">1</tt>.</p></dd><dt><span class="term"><tt class="methodname">createProcessingInstruction</tt></span></dt><dd><div class="tclcmdsynopsis" id="id319981"><a name="id319981"></a>
152	      <tt class="methodname">createProcessingInstruction</tt>
153	      <i class="replaceable"><tt>token</tt></i>
154	       <i class="replaceable"><tt>target</tt></i>
155	       <i class="replaceable"><tt>data</tt></i>
156	    </div><p>This method creates a processingInstruction node as a child of the given node specified by <tt class="option"><i class="replaceable"><tt>token</tt></i></tt>.  <tt class="option"><i class="replaceable"><tt>token</tt></i></tt> must be a node of type element, document or documentFragment.  The new, child processingInstruction is added as the last child of <tt class="option"><i class="replaceable"><tt>token</tt></i></tt>'s list of children.  The new node is created with its name set to <tt class="option"><i class="replaceable"><tt>target</tt></i></tt> and its value set to <tt class="option"><i class="replaceable"><tt>data</tt></i></tt>.</p></dd><dt><span class="term"><tt class="methodname">createAttribute</tt></span></dt><dd><div class="tclcmdsynopsis" id="id320083"><a name="id320083"></a>
157	      <tt class="methodname">createAttribute</tt>
158	      <i class="replaceable"><tt>token</tt></i>
159	       <i class="replaceable"><tt>name</tt></i>
160	    </div><p>This method creates an attribute node for the given element specified by <tt class="option"><i class="replaceable"><tt>token</tt></i></tt>.  <tt class="option"><i class="replaceable"><tt>token</tt></i></tt> must be a node of type element.  The new attribute is created with its name set to <tt class="option"><i class="replaceable"><tt>name</tt></i></tt> and an empty value.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>This method is included for completeness with respect to the DOM specification.  The preferred method for setting element attributes is to use the <a href="#__dom__element"><b class="tclcommand">::dom::element</b></a> command.</p></div></dd><dt><span class="term"><tt class="methodname">createEntity</tt></span></dt><dd><div class="tclcmdsynopsis" id="id320177"><a name="id320177"></a>
161	      <tt class="methodname">createEntity</tt>
162	      <i class="replaceable"><tt>token</tt></i>
163	    </div><p>Not currently implemented.</p></dd><dt><span class="term"><tt class="methodname">createEntityReference</tt></span></dt><dd><div class="tclcmdsynopsis" id="id320219"><a name="id320219"></a>
164	      <tt class="methodname">createEntityReference</tt>
165	      <i class="replaceable"><tt>token</tt></i>
166	       <i class="replaceable"><tt>name</tt></i>
167	    </div><p>Not currently implemented.</p></dd><dt><span class="term"><tt class="methodname">createDocTypeDecl</tt></span></dt><dd><div class="tclcmdsynopsis" id="id320273"><a name="id320273"></a>
168	      <tt class="methodname">createDocTypeDecl</tt>
169	      <i class="replaceable"><tt>token</tt></i>
170	       <i class="replaceable"><tt>name</tt></i>
171	       <i class="replaceable"><tt>extid</tt></i>
172	       <i class="replaceable"><tt>dtd</tt></i>
173	       <i class="replaceable"><tt>entities</tt></i>
174	       <i class="replaceable"><tt>notations</tt></i>
175	    </div><p>This method creates a Document Type Declaration node as a child of the given node specified by <tt class="option"><i class="replaceable"><tt>token</tt></i></tt>.  <tt class="option"><i class="replaceable"><tt>token</tt></i></tt> must be a node of type document.  <tt class="option"><i class="replaceable"><tt>name</tt></i></tt> is the element type of the document element.  If the document already has a document element then this name must match with that element type.  <tt class="option"><i class="replaceable"><tt>extid</tt></i></tt> is an external identifier to include in the document type declaration.  <tt class="option"><i class="replaceable"><tt>dtd</tt></i></tt> is an internal DTD subset to include in the document type declaration.  This is specified as XML text.  <tt class="option"><i class="replaceable"><tt>entities</tt></i></tt> and <tt class="option"><i class="replaceable"><tt>notations</tt></i></tt> are included for completeness with the DOM specification, but are not currently implemented.</p><p><span class="emphasis"><em>Non-standard:</em></span> This method is not a standard method as specified by the DOM Recommendation, see <a href="#__dom__DOMImplementation_createDocumentType"><b class="tclcommand">::dom::DOMImplementation <tt class="methodname">createDocumentType</tt></b></a>.</p></dd><dt><span class="term"><tt class="methodname">createEvent</tt></span></dt><dd><div class="tclcmdsynopsis" id="id320446"><a name="id320446"></a>
176	      <tt class="methodname">createEvent</tt>
177	      <i class="replaceable"><tt>token</tt></i>
178	       <i class="replaceable"><tt>name</tt></i>
179	    </div><p>This method creates an event node in the document specified by <tt class="option"><i class="replaceable"><tt>token</tt></i></tt>.  <tt class="option"><i class="replaceable"><tt>token</tt></i></tt> must be a node of type document.  The event type is specified by <tt class="option"><i class="replaceable"><tt>name</tt></i></tt>.</p></dd><dt><span class="term"><tt class="methodname">getElementsByTagName</tt></span></dt><dd><div class="tclcmdsynopsis" id="id320520"><a name="id320520"></a>
180	      <tt class="methodname">getElementsByTagName</tt>
181	      <i class="replaceable"><tt>token</tt></i>
182	       <i class="replaceable"><tt>name</tt></i>
183	    </div><p>This method searches the node given by the argument <tt class="option"><i class="replaceable"><tt>token</tt></i></tt> for child elements with a type matching the argument <tt class="option"><i class="replaceable"><tt>name</tt></i></tt>.  The name <tt class="literal">*</tt> matches all elements.  All descendants of <tt class="option"><i class="replaceable"><tt>token</tt></i></tt> are searched.  This method returns a &quot;live-list&quot;; the return result of this method is the name of a Tcl variable, the content of which is a Tcl list containing tokens for all elements that match.</p></dd></dl></div></div><div class="refsect2" lang="en"><h3><a href="#dom__node"><b class="tclcommand">dom::node</b></a></h3><p>This command implements generic functions for DOM nodes.</p><p>The methods accepted by this command are as follows:</p><div class="variablelist"><dl><dt><span class="term"><tt class="methodname">cget</tt></span></dt><dd><div class="tclcmdsynopsis" id="id320635"><a name="id320635"></a>
184	      <tt class="methodname">cget</tt>
185	      <i class="replaceable"><tt>token</tt></i>
186	       option
187	    </div><p>This method returns the value of the given configuration option for the node given by <tt class="option"><i class="replaceable"><tt>token</tt></i></tt>.</p></dd><dt><span class="term"><tt class="methodname">configure</tt></span></dt><dd><div class="tclcmdsynopsis" id="id320694"><a name="id320694"></a>
188	      <tt class="methodname">configure</tt>
189	      <i class="replaceable"><tt>token</tt></i>
190	      ?<i class="replaceable"><tt>option</tt></i> <i class="replaceable"><tt>value</tt></i>...?
191	    </div><p>This method sets the value of the given configuration option for the node given by <tt class="option"><i class="replaceable"><tt>token</tt></i></tt>.</p><p>Valid configuration options are as follows:</p><div class="variablelist"><dl><dt><span class="term">[-nodeName]</span></dt><dd><p>Returns the node name.  This is a read-only option.</p><p>The DOM specification gives the meaning of names for different types of nodes.  For example, the <tt class="option">-nodeName</tt> option of an element node is the element type.</p></dd><dt><span class="term">[-nodeType]</span></dt><dd><p>Returns the type of the node given by <tt class="option"><i class="replaceable"><tt>token</tt></i></tt>.  This is a read-only option.</p></dd><dt><span class="term"><tt class="option">-parentNode</tt></span></dt><dd><p>Returns the parent node of the node given by <tt class="option"><i class="replaceable"><tt>token</tt></i></tt>.  This is a read-only option.</p></dd><dt><span class="term"><tt class="option">-childNodes</tt></span></dt><dd><p>Returns the name of a Tcl variable which contains a list of the children of the node given by <tt class="option"><i class="replaceable"><tt>token</tt></i></tt>.  The variable contains the &quot;live&quot; list of children.  This is a read-only option.</p></dd><dt><span class="term"><tt class="option">-firstChild</tt></span></dt><dd><p>Returns the first child node of the node given by <tt class="option"><i class="replaceable"><tt>token</tt></i></tt>.  This is a read-only option.</p></dd><dt><span class="term"><tt class="option">-lastChild</tt></span></dt><dd><p>Returns the last child node of the node given by <tt class="option"><i class="replaceable"><tt>token</tt></i></tt>.  This is a read-only option.</p></dd><dt><span class="term"><tt class="option">-previousSibling</tt></span></dt><dd><p>Returns the parent's child node which appears before this node.  If this child is the first child of its parent then returns an empty string.  This is a read-only option.</p></dd><dt><span class="term"><tt class="option">-nextSibling</tt></span></dt><dd><p>Returns the parent's child node which appears after this node.  If this child is the last child of its parent then returns an empty string.  This is a read-only option.</p></dd><dt><span class="term"><tt class="option">-attributes</tt></span></dt><dd><p>Returns the name of a Tcl array variable which contains the attribute list for an element node.  If the node is not an element type node then returns an empty string.  The indices of the array are attribute names, and the values of the array elements are their corresponding attribute values.  This is a read-only option.</p></dd><dt><span class="term"><tt class="option">-nodeValue</tt>  [<i class="replaceable"><tt>data</tt></i>]</span></dt><dd><p>Specifies the value of a node.  The DOM specification gives the meaning of values for different types of nodes.  For example, the <tt class="option">-nodeValue</tt> option of a textNode node is the node's text.</p></dd></dl></div></dd></dl></div></div><div class="refsect2" lang="en"><h3><a href="#dom__element"><b class="tclcommand">dom::element</b></a></h3><p>This command provides functions for element type nodes.</p><p>Valid methods for this command are as follows:</p><div class="variablelist"><dl><dt><span class="term"><tt class="methodname">cget</tt></span></dt><dd><div class="tclcmdsynopsis" id="id321756"><a name="id321756"></a>
192	      <tt class="methodname">cget</tt>
193	      <i class="replaceable"><tt>token</tt></i>
194	       <i class="replaceable"><tt>option</tt></i>
195	    </div><p>This method returns the current setting of configuration options for an element.  See the <tt class="methodname">configure</tt> method for the list of valid configuration options.</p></dd><dt><span class="term"><tt class="methodname">configure</tt></span></dt><dd><div class="tclcmdsynopsis" id="id321816"><a name="id321816"></a>
196	      <tt class="methodname">configure</tt>
197	      <i class="replaceable"><tt>token</tt></i>
198	      ?<i class="replaceable"><tt>option</tt></i> <i class="replaceable"><tt>value</tt></i>...?
199	    </div><p>This method sets configuration options for an element.  Note that element type nodes only have read-only options.</p><p>Valid configuration options are as follows:</p><div class="variablelist"><dl><dt><span class="term"><tt class="option">-tagName</tt>  [<i class="replaceable"><tt>name</tt></i>]</span></dt><dd>The tag name, or element type, of this element.</dd><dt><span class="term"><tt class="option">-empty</tt>  [<i class="replaceable"><tt>boolean</tt></i>]</span></dt><dd><p>Sets whether this element was specified as an empty element when the document was parsed.  That is, XML empty element syntax such as <tt class="literal">&lt;Empty/&gt;</tt> was used.</p><p>This option has no effect upon output (serialization) of the XML document.  Empty element syntax is automatically used where appropriate.</p></dd></dl></div></dd><dt><span class="term"><tt class="methodname">getAttribute</tt></span></dt><dd><div class="tclcmdsynopsis" id="id321979"><a name="id321979"></a>
200	      <tt class="methodname">getAttribute</tt>
201	      <i class="replaceable"><tt>token</tt></i>
202	       <i class="replaceable"><tt>name</tt></i>
203	    </div><p>This method returns the attribute value of the attribute given by <tt class="option"><i class="replaceable"><tt>name</tt></i></tt>.  If the attribute does not exist, then an empty string is returned.</p></dd><dt><span class="term"><tt class="methodname">setAttribute</tt></span></dt><dd><div class="tclcmdsynopsis" id="id322041"><a name="id322041"></a>
204	      <tt class="methodname">setAttribute</tt>
205	      <i class="replaceable"><tt>token</tt></i>
206	       <i class="replaceable"><tt>name</tt></i>
207	       <i class="replaceable"><tt>value</tt></i>
208	    </div><p>This method sets the attribute value of the attribute given by <tt class="option"><i class="replaceable"><tt>name</tt></i></tt>.  If the attribute already exists then its value is replaced, otherwise the attribute is created.</p></dd><dt><span class="term"><tt class="methodname">removeAttribute</tt></span></dt><dd><div class="tclcmdsynopsis" id="id322115"><a name="id322115"></a>
209	      <tt class="methodname">removeAttribute</tt>
210	      <i class="replaceable"><tt>token</tt></i>
211	       <i class="replaceable"><tt>name</tt></i>
212	    </div><p>This method deletes the attribute given by <tt class="option"><i class="replaceable"><tt>name</tt></i></tt>.  If the attribute does not exist then the method has no effect.</p></dd><dt><span class="term"><tt class="methodname">getAttributeNode</tt></span></dt><dd><div class="tclcmdsynopsis" id="id322176"><a name="id322176"></a>
213	      <tt class="methodname">getAttributeNode</tt>
214	      <i class="replaceable"><tt>token</tt></i>
215	       <i class="replaceable"><tt>name</tt></i>
216	    </div><p>Not implemented.</p></dd><dt><span class="term"><tt class="methodname">setAttributeNode</tt></span></dt><dd><div class="tclcmdsynopsis" id="id322230"><a name="id322230"></a>
217	      <tt class="methodname">setAttributeNode</tt>
218	      <i class="replaceable"><tt>token</tt></i>
219	       <i class="replaceable"><tt>name</tt></i>
220	    </div><p>Not implemented.</p></dd><dt><span class="term"><tt class="methodname">removeAttributeNode</tt></span></dt><dd><div class="tclcmdsynopsis" id="id322284"><a name="id322284"></a>
221	      <tt class="methodname">removeAttributeNode</tt>
222	      <i class="replaceable"><tt>token</tt></i>
223	       <i class="replaceable"><tt>name</tt></i>
224	    </div><p>Not implemented.</p></dd><dt><span class="term"><tt class="methodname">getElementsByTagName</tt></span></dt><dd><div class="tclcmdsynopsis" id="id322338"><a name="id322338"></a>
225	      <tt class="methodname">getElementsByTagName</tt>
226	      <i class="replaceable"><tt>token</tt></i>
227	       <i class="replaceable"><tt>name</tt></i>
228	    </div><p>This method searches the node given by the argument <tt class="option"><i class="replaceable"><tt>token</tt></i></tt> for descendant child elements with a type matching the argument <tt class="option"><i class="replaceable"><tt>name</tt></i></tt>.  The wildcard character <tt class="literal">*</tt> matches any element type.  The return result is a &quot;live-list&quot; which is represented by a Tcl variable.  This method returns the name of the Tcl variable that contains the list of tokens that match.</p></dd><dt><span class="term"><tt class="methodname">normalize</tt></span></dt><dd><div class="tclcmdsynopsis" id="id322417"><a name="id322417"></a>
229	      <tt class="methodname">normalize</tt>
230	      <i class="replaceable"><tt>token</tt></i>
231	    </div><p>This method recursively coalesces textNodes within the children of the given node.  textNodes which are adjacent in the DOM tree cannot be distinguished in the serialized XML document.</p></dd></dl></div></div><div class="refsect2" lang="en"><h3><a href="#dom__processinginstruction"><b class="tclcommand">dom::processinginstruction</b></a></h3><p>This command provides functions for processingInstruction type nodes.</p><p>Valid methods for this command are as follows:</p><div class="variablelist"><dl><dt><span class="term"><tt class="methodname">cget</tt></span></dt><dd><div class="tclcmdsynopsis" id="id322492"><a name="id322492"></a>
232	      <tt class="methodname">cget</tt>
233	      <i class="replaceable"><tt>token</tt></i>
234	       <i class="replaceable"><tt>option</tt></i>
235	    </div><p>This method returns the current setting of configuration options for an element.  See the <tt class="methodname">configure</tt> method for the list of valid configuration options.</p></dd><dt><span class="term"><tt class="methodname">configure</tt></span></dt><dd><div class="tclcmdsynopsis" id="id322552"><a name="id322552"></a>
236	      <tt class="methodname">configure</tt>
237	      <i class="replaceable"><tt>token</tt></i>
238	      ?<i class="replaceable"><tt>option</tt></i> <i class="replaceable"><tt>value</tt></i>...?
239	    </div><p>This method sets configuration options for a processing instruction.</p><p>Valid configuration options are as follows:</p><div class="variablelist"><dl><dt><span class="term"><tt class="option">-target</tt>  [<i class="replaceable"><tt>name</tt></i>]</span></dt><dd>This option sets the target of the processing instruction.  This is a read-only configuration option.</dd><dt><span class="term"><tt class="option">-data</tt>  [<i class="replaceable"><tt>data</tt></i>]</span></dt><dd><p>This option sets the data of the processing instruction.</p></dd></dl></div></dd></dl></div></div><div class="refsect2" lang="en"><h3><a href="#dom__event"><b class="tclcommand">dom::event</b></a></h3><p>This command provides functions for event type nodes.</p><p>Valid methods for this command are as follows:</p><div class="variablelist"><dl><dt><span class="term"><tt class="methodname">cget</tt></span></dt><dd><div class="tclcmdsynopsis" id="id322728"><a name="id322728"></a>
240	      <tt class="methodname">cget</tt>
241	      <i class="replaceable"><tt>token</tt></i>
242	    </div><p>This method retrieves configuration options for an event.</p><p>Valid configuration options are as follows:</p><div class="variablelist"><dl><dt><span class="term"><tt class="option">-altKey</tt></span></dt><dd>This option determines whether the ALT modifier key has been specified for this event.</dd><dt><span class="term"><tt class="option">-timeStamp</tt></span></dt><dd><p>This option gives the time at which the event was posted.  The value is the number of milliseconds since the epoch, which is compatible with the Tcl <b class="command">clock</b> command.  </p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3>The implementation of this method depends on the <tt class="methodname">Tcl_GetTime</tt> function.This function only became publically available in Tcl 8.4.  If a version of Tcl prior to 8.4 is being used, then this option will have the value <tt class="literal">0</tt>.</div></dd></dl></div></dd><dt><span class="term"><tt class="methodname">configure</tt></span></dt><dd><div class="tclcmdsynopsis" id="id322848"><a name="id322848"></a>
243	      <tt class="methodname">configure</tt>
244	      <i class="replaceable"><tt>token</tt></i>
245	      ?<i class="replaceable"><tt>option</tt></i> <i class="replaceable"><tt>value</tt></i>...?
246	    </div><p>This method sets the configuration options for an event.  See the <tt class="methodname">cget</tt> method for the list of valid configuration options.</p></dd></dl></div></div></div><div class="refsect1" lang="en"><h2>Implementations</h2><p>This section documents the various implmentations of the TclDOM API.</p><div class="refsect2" lang="en"><h3>Tcl Implementation</h3><p>The Tcl implementation is provided by the <tt class="tclpackage">dom::tcl</tt> package.</p><p>It is a reference implementation, and implements the TclDOM API as described above.</p><p>A DOM tree using this implementation may be created using the <a href="#dom__tcl__create"><b class="tclcommand">dom::tcl::create</b></a> command.</p></div><div class="refsect2" lang="en"><h3>libxml2 Implementation</h3><p>The TclDOM/libxml2 implementation is a wrapper for the <a href="http://xmlsoft.org/" target="_top">Gnome libxml2 library</a>.  It is provided by the <tt class="tclpackage">dom::libxml2</tt> package.  It is a high-performance library, making use of Tcl objects for fast access to tree nodes.</p><p>A DOM tree using this implementation may be created using the <a href="#dom__libxml2__create"><b class="tclcommand">dom::libxml2::create</b></a> command.</p><p></p><div class="refsect3" lang="en"><h4>Notes</h4><div class="itemizedlist"><ul type="disc"><li><p>The <a href="#dom__libxml2__parse"><b class="tclcommand">dom::libxml2::parse</b></a> command is linked directly to the libxml2 parser.  It is not possible to specify TclXML configuration options (ie. callbacks).  The following configuration options are valid:</p><div class="variablelist"><dl><dt><span class="term"><tt class="option">-- fill this in --</tt></span></dt><dd><p>-- fill this in --</p></dd></dl></div></li><li><p>The implementation of most of the commands are incomplete.  Missing methods and options will be documented here...</p></li></ul></div></div></div></div></div></body></html>
247