<!DOCTYPE refentry [
  <!ENTITY version "@PACKAGE_VERSION@">
]>
<refentry xmlns="http://docbook.org/ns/docbook">
  <d:info xmlns:d="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:tcl="http://tclxml.sourceforge.net/doc">
    <author xlink:href="http://www.explain.com.au/staff/Steve.Ball/">
      <firstname>Steve</firstname>
      <surname>Ball</surname>
    </author>
    <copyright>
      <year>2007</year>
      <year>2005</year>
      <holder xlink:href="http://www.explain.com.au/">Explain</holder>
    </copyright>
    <copyright>
      <year>2004</year>
      <year>2003</year>
      <year>2000</year>
      <holder xlink:href="http://www.zveno.com/">Zveno Pty Ltd</holder>
    </copyright>
    <legalnotice>
      <para>See the file "LICENSE" for information on usage and redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.</para>
    </legalnotice>
    <revhistory>
      <revision>
        <revnumber>3.2</revnumber>
        <date>2007-12-11</date>
        <authorinitials>SRB</authorinitials>
        <revremark>Updated author details and legal notice.</revremark>
      </revision>
      <revision>
        <revnumber>3.1</revnumber>
        <date>2005-03-02</date>
        <authorinitials>SRB</authorinitials>
        <revremark>Updated details on -externalentitycommand callback.  Fixed minor typo.</revremark>
      </revision>
      <revision>
        <revnumber>3.0</revnumber>
        <date>2003-08-22</date>
        <authorinitials>SRB</authorinitials>
        <revremark>Added libxml2 parser class.</revremark>
      </revision>
    </revhistory>
  </d:info>
  <refmeta>
    <refentrytitle>TclXML</refentrytitle>
    <manvolnum>n</manvolnum>
  </refmeta>
  <refnamediv>
    <refname>TclXML</refname>
    <refpurpose>XML parser support for Tcl</refpurpose>
  </refnamediv>
  <refsynopsisdiv>
    <cmdsynopsis xmlns="http://tclxml.sourceforge.net/doc">
      <command xmlns="http://docbook.org/ns/docbook">package require xml</command>
    </cmdsynopsis>
    <cmdsynopsis xmlns="http://tclxml.sourceforge.net/doc">
      <command xmlns="http://docbook.org/ns/docbook">package require <replaceable>parserclass</replaceable></command>
    </cmdsynopsis>
    <pkgsynopsis xmlns="http://tclxml.sourceforge.net/doc">
      <package xmlns="http://docbook.org/ns/docbook">xml</package>
      <version xmlns="http://docbook.org/ns/docbook">&version;</version>
    </pkgsynopsis>
    <namespacesynopsis xmlns="http://tclxml.sourceforge.net/doc">
      <namespace>::xml</namespace>
      <namespace>::sgml</namespace>
      <namespace>::xml::tclparser</namespace>
      <namespace>::xml::libxml2</namespace>
    </namespacesynopsis>
    <cmdsynopsis xmlns="http://tclxml.sourceforge.net/doc">
      <command xmlns="http://docbook.org/ns/docbook">::xml::parserclass</command>
      <option xmlns="http://docbook.org/ns/docbook">option</option>
      <group xmlns="http://docbook.org/ns/docbook" choice="opt" rep="repeat">
        <arg>arg</arg>
        <arg>arg</arg>
      </group>
    </cmdsynopsis>
    <cmdsynopsis xmlns="http://tclxml.sourceforge.net/doc">
      <command xmlns="http://docbook.org/ns/docbook">::xml::parser</command>
      <group xmlns="http://docbook.org/ns/docbook" choice="opt">
        <arg>
          <replaceable>name</replaceable>
        </arg>
      </group>
      <group xmlns="http://docbook.org/ns/docbook" choice="opt" rep="repeat">
        <option>-option</option>
        <arg>
          <replaceable>value</replaceable>
        </arg>
      </group>
    </cmdsynopsis>
    <cmdsynopsis xmlns="http://tclxml.sourceforge.net/doc">
      <command xmlns="http://docbook.org/ns/docbook">
        <replaceable>parser</replaceable>
      </command>
      <arg xmlns="http://docbook.org/ns/docbook">
        <replaceable>option</replaceable>
      </arg>
      <arg xmlns="http://docbook.org/ns/docbook" rep="repeat" choice="opt">
        <replaceable>arg</replaceable>
      </arg>
    </cmdsynopsis>
  </refsynopsisdiv>
  <refsect1>
    <d:info xmlns:d="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:tcl="http://tclxml.sourceforge.net/doc">
      <d:title>Description</d:title>
    </d:info>
    <para>TclXML provides event-based parsing of <acronym xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.w3.org/XML/">XML</acronym> documents.  The application may register callback scripts for certain document features, and when the parser encounters those features while parsing the document the callback is evaluated.</para>
    <para>The parser may also perform other functions, such as normalisation, validation and/or entity expansion.  Generally, these functions are under the control of configuration options.  Whether these functions can be performed at all depends on the parser implementation.</para>
    <para>The TclXML package provides a generic interface for use by a Tcl application, along with a low-level interface for use by a parser implementation.  Each implementation provides a class of XML parser, and these register themselves using the <command xmlns="http://tclxml.sourceforge.net/doc">::xml::parserclass create</command> command.  One of the registered parser classes will be the default parser class.</para>
    <para>Loading the package with the generic <command xmlns="http://tclxml.sourceforge.net/doc">package require xml</command> command allows the package to automatically determine the default parser class.  In order to select a particular parser class as the default, that class' package may be loaded directly, eg. <command xmlns="http://tclxml.sourceforge.net/doc">package require xml::libxml2</command>.  In all cases, all available parser classes are registered with the TclXML package, the difference is simply in which one becomes the default.</para>
  </refsect1>
  <refsect1>
    <d:info xmlns:d="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:tcl="http://tclxml.sourceforge.net/doc">
      <d:title>Commands</d:title>
    </d:info>
    <refsect2>
      <d:info xmlns:d="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:tcl="http://tclxml.sourceforge.net/doc">
        <d:title>
          <command xmlns="http://tclxml.sourceforge.net/doc">::xml::parserclass</command>
        </d:title>
      </d:info>
      <para>The <command xmlns="http://tclxml.sourceforge.net/doc">::xml::parserclass</command> command is used to manage XML parser classes.</para>
      <refsect3>
        <d:info xmlns:d="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:tcl="http://tclxml.sourceforge.net/doc">
          <d:title>Command Options</d:title>
        </d:info>
        <para>The following command options may be used:</para>
        <variablelist>
          <varlistentry>
            <term>
              <methodname>create</methodname>
            </term>
            <listitem>
              <cmdsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <arg xmlns="http://docbook.org/ns/docbook">create</arg>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable class="parameter">name</replaceable>
                </arg>
                <group xmlns="http://docbook.org/ns/docbook" choice="opt">
                  <option>-createcommand</option>
                  <arg>
                    <replaceable>script</replaceable>
                  </arg>
                </group>
                <group xmlns="http://docbook.org/ns/docbook" choice="opt">
                  <option>-createentityparsercommand</option>
                  <arg>
                    <replaceable>script</replaceable>
                  </arg>
                </group>
                <group xmlns="http://docbook.org/ns/docbook" choice="opt">
                  <option>-parsecommand</option>
                  <arg>
                    <replaceable>script</replaceable>
                  </arg>
                </group>
                <group xmlns="http://docbook.org/ns/docbook" choice="opt">
                  <option>-configurecommand</option>
                  <arg>
                    <replaceable>script</replaceable>
                  </arg>
                </group>
                <group xmlns="http://docbook.org/ns/docbook" choice="opt">
                  <option>-getcommand</option>
                  <arg>
                    <replaceable>script</replaceable>
                  </arg>
                </group>
                <group xmlns="http://docbook.org/ns/docbook" choice="opt">
                  <option>-deletecommand</option>
                  <arg>
                    <replaceable>script</replaceable>
                  </arg>
                </group>
              </cmdsynopsis>
              <para>Creates an XML parser class with the given name.</para>
            </listitem>
          </varlistentry>
          <varlistentry>
            <term>
              <methodname>destroy</methodname>
            </term>
            <listitem>
              <cmdsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <arg xmlns="http://docbook.org/ns/docbook">destroy</arg>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>name</replaceable>
                </arg>
              </cmdsynopsis>
              <para>Destroys an XML parser class.</para>
            </listitem>
          </varlistentry>
          <varlistentry>
            <term>
              <methodname>info</methodname>
            </term>
            <listitem>
              <cmdsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <option xmlns="http://docbook.org/ns/docbook">info</option>
                <group xmlns="http://docbook.org/ns/docbook" choice="req">
                  <arg>names</arg>
                  <arg>default</arg>
                </group>
              </cmdsynopsis>
              <para>Returns information about registered XML parser classes.</para>
            </listitem>
          </varlistentry>
        </variablelist>
      </refsect3>
    </refsect2>
    <refsect2>
      <d:info xmlns:d="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:tcl="http://tclxml.sourceforge.net/doc">
        <d:title>
          <command xmlns="http://tclxml.sourceforge.net/doc">::xml::parser</command>
        </d:title>
      </d:info>
      <para>The <command xmlns="http://tclxml.sourceforge.net/doc">::xml::parser</command> command creates an <acronym>XML</acronym> parser object.  The return value of the command is the name of the newly created parser.</para>
      <para>The parser scans an XML document's syntactical structure, evaluating callback scripts for each feature found.  At the very least the parser will normalise the document and check the document for well-formedness.  If the document is not well-formed then the <option>-errorcommand</option> option will be evaluated.  Some parser classes may perform additional functions, such as validation.  Additional features provided by the various parser classes are described in the section Parser Classes</para>
      <para>Parsing is performed synchronously.  The command blocks until the entire document has been parsed.  Parsing may be terminated by an application callback, see the section Callback Return Codes.  Incremental parsing is also supported by using the <option>-final</option> configuration option.</para>
      <refsect3>
        <d:info xmlns:d="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:tcl="http://tclxml.sourceforge.net/doc">
          <d:title>Configuration Options</d:title>
        </d:info>
        <para>The <command xmlns="http://tclxml.sourceforge.net/doc">::xml::parser</command> command accepts the following configuration options:</para>
        <variablelist>
          <varlistentry>
            <term>
              <option>-attlistdeclcommand</option>
            </term>
            <listitem>
              <optionsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <option xmlns="http://docbook.org/ns/docbook">-attlistdeclcommand</option>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>script</replaceable>
                </arg>
              </optionsynopsis>
              <para>Specifies the prefix of a Tcl command to be evaluated whenever an attribute list declaration is encountered in the DTD subset of an XML document.  The command evaluated is:</para>
              <cmdsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <command xmlns="http://docbook.org/ns/docbook">
                  <replaceable>script</replaceable>
                </command>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>name</replaceable>
                </arg>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>attrname</replaceable>
                </arg>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>type</replaceable>
                </arg>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>default</replaceable>
                </arg>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>value</replaceable>
                </arg>
              </cmdsynopsis>
              <para>where:</para>
              <segmentedlist>
                <seglistitem>
                  <seg>
                    <arg>
                      <replaceable>name</replaceable>
                    </arg>
                  </seg>
                  <seg>Element type name</seg>
                </seglistitem>
                <seglistitem>
                  <seg>
                    <arg>
                      <replaceable>attrname</replaceable>
                    </arg>
                  </seg>
                  <seg>Attribute name being declared</seg>
                </seglistitem>
                <seglistitem>
                  <seg>
                    <arg>
                      <replaceable>type</replaceable>
                    </arg>
                  </seg>
                  <seg>Attribute type</seg>
                </seglistitem>
                <seglistitem>
                  <seg>
                    <arg>
                      <replaceable>default</replaceable>
                    </arg>
                  </seg>
                  <seg>Attribute default, such as #IMPLIED</seg>
                </seglistitem>
                <seglistitem>
                  <seg>
                    <arg>
                      <replaceable>value</replaceable>
                    </arg>
                  </seg>
                  <seg>Default attribute value.  Empty string if none given.</seg>
                </seglistitem>
              </segmentedlist>
            </listitem>
          </varlistentry>
          <varlistentry>
            <term>
              <option>-baseuri</option>
            </term>
            <term>
              <option>-baseurl</option>
            </term>
            <listitem>
              <optionsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <option xmlns="http://docbook.org/ns/docbook">-baseuri</option>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>URI</replaceable>
                </arg>
              </optionsynopsis>
              <optionsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <option xmlns="http://docbook.org/ns/docbook">-baseurl</option>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>URI</replaceable>
                </arg>
              </optionsynopsis>
              <para>Specifies the base URI for resolving relative URIs that may be used in the XML document to refer to external entities.</para>
              <para><option>-baseurl</option> is deprecated in favour of <option>-baseuri</option>.</para>
            </listitem>
          </varlistentry>
          <varlistentry>
            <term>
              <option>-characterdatacommand</option>
            </term>
            <listitem>
              <optionsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <option xmlns="http://docbook.org/ns/docbook">-characterdatacommand</option>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>script</replaceable>
                </arg>
              </optionsynopsis>
              <para>Specifies the prefix of a Tcl command to be evaluated whenever character data is encountered in the XML document being parsed.  The command evaluated is:</para>
              <cmdsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <command xmlns="http://docbook.org/ns/docbook">
                  <replaceable>script</replaceable>
                </command>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>data</replaceable>
                </arg>
              </cmdsynopsis>
              <para>where:</para>
              <segmentedlist>
                <seglistitem>
                  <seg>
                    <arg>
                      <replaceable>data</replaceable>
                    </arg>
                  </seg>
                  <seg>Character data in the document</seg>
                </seglistitem>
              </segmentedlist>
            </listitem>
          </varlistentry>
          <varlistentry>
            <term>
              <option>-commentcommand</option>
            </term>
            <listitem>
              <optionsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <option xmlns="http://docbook.org/ns/docbook">-commentcommand</option>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>script</replaceable>
                </arg>
              </optionsynopsis>
              <para>Specifies the prefix of a Tcl command to be evaluated whenever a comment is encountered in the XML document being parsed.  The command evaluated is:</para>
              <cmdsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <command xmlns="http://docbook.org/ns/docbook">
                  <replaceable>script</replaceable>
                </command>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>data</replaceable>
                </arg>
              </cmdsynopsis>
              <para>where:</para>
              <segmentedlist>
                <seglistitem>
                  <seg>
                    <arg>
                      <replaceable>data</replaceable>
                    </arg>
                  </seg>
                  <seg>Comment data</seg>
                </seglistitem>
              </segmentedlist>
            </listitem>
          </varlistentry>
          <varlistentry>
            <term>
              <option>-defaultcommand</option>
            </term>
            <listitem>
              <optionsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <option xmlns="http://docbook.org/ns/docbook">-defaultcommand</option>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>script</replaceable>
                </arg>
              </optionsynopsis>
              <para>Specifies the prefix of a Tcl command to be evaluated when no other callback has been defined for a document feature which has been encountered.  The command evaluated is:</para>
              <cmdsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <command xmlns="http://docbook.org/ns/docbook">
                  <replaceable>script</replaceable>
                </command>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>data</replaceable>
                </arg>
              </cmdsynopsis>
              <para>where:</para>
              <segmentedlist>
                <seglistitem>
                  <seg>
                    <arg>
                      <replaceable>data</replaceable>
                    </arg>
                  </seg>
                  <seg>Document data</seg>
                </seglistitem>
              </segmentedlist>
            </listitem>
          </varlistentry>
          <varlistentry>
            <term>
              <option>-defaultexpandinternalentities</option>
            </term>
            <listitem>
              <optionsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <option xmlns="http://docbook.org/ns/docbook">-defaultexpandinternalentities</option>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>boolean</replaceable>
                </arg>
              </optionsynopsis>
              <para>Specifies whether entities declared in the internal DTD subset are expanded with their replacement text.  If entities are not expanded then the entity references will be reported with no expansion.</para>
            </listitem>
          </varlistentry>
          <varlistentry>
            <term>
              <option>-doctypecommand</option>
            </term>
            <listitem>
              <optionsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <option xmlns="http://docbook.org/ns/docbook">-doctypecommand</option>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>script</replaceable>
                </arg>
              </optionsynopsis>
              <para>Specifies the prefix of a Tcl command to be evaluated when the document type declaration is encountered.  The command evaluated is:</para>
              <cmdsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <command xmlns="http://docbook.org/ns/docbook">
                  <replaceable>script</replaceable>
                </command>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>name</replaceable>
                </arg>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>public</replaceable>
                </arg>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>system</replaceable>
                </arg>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>dtd</replaceable>
                </arg>
              </cmdsynopsis>
              <para>where:</para>
              <segmentedlist>
                <seglistitem>
                  <seg>
                    <arg>
                      <replaceable>name</replaceable>
                    </arg>
                  </seg>
                  <seg>The name of the document element</seg>
                </seglistitem>
                <seglistitem>
                  <seg>
                    <arg>
                      <replaceable>public</replaceable>
                    </arg>
                  </seg>
                  <seg>Public identifier for the external DTD subset</seg>
                </seglistitem>
                <seglistitem>
                  <seg>
                    <arg>
                      <replaceable>system</replaceable>
                    </arg>
                  </seg>
                  <seg>System identifier for the external DTD subset.  Usually a URI.</seg>
                </seglistitem>
                <seglistitem>
                  <seg>
                    <arg>
                      <replaceable>dtd</replaceable>
                    </arg>
                  </seg>
                  <seg>The internal DTD subset</seg>
                </seglistitem>
              </segmentedlist>
              <para>See also <option>-startdoctypedeclcommand</option> and <option>-enddoctypedeclcommand</option>.</para>
            </listitem>
          </varlistentry>
          <varlistentry>
            <term>
              <option>-elementdeclcommand</option>
            </term>
            <listitem>
              <optionsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <option xmlns="http://docbook.org/ns/docbook">-elementdeclcommand</option>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>script</replaceable>
                </arg>
              </optionsynopsis>
              <para>Specifies the prefix of a Tcl command to be evaluated when an element markup declaration is encountered.  The command evaluated is:</para>
              <cmdsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <command xmlns="http://docbook.org/ns/docbook">
                  <replaceable>script</replaceable>
                </command>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>name</replaceable>
                </arg>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>model</replaceable>
                </arg>
              </cmdsynopsis>
              <para>where:</para>
              <segmentedlist>
                <seglistitem>
                  <seg>
                    <arg>
                      <replaceable>name</replaceable>
                    </arg>
                  </seg>
                  <seg>The element type name</seg>
                </seglistitem>
                <seglistitem>
                  <seg>
                    <arg>
                      <replaceable>model</replaceable>
                    </arg>
                  </seg>
                  <seg>Content model specification</seg>
                </seglistitem>
              </segmentedlist>
            </listitem>
          </varlistentry>
          <varlistentry>
            <term>
              <option>-elementendcommand</option>
            </term>
            <listitem>
              <optionsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <option xmlns="http://docbook.org/ns/docbook">-elementendcommand</option>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>script</replaceable>
                </arg>
              </optionsynopsis>
              <para>Specifies the prefix of a Tcl command to be evaluated when an element end tag is encountered.  The command evaluated is:</para>
              <cmdsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <command xmlns="http://docbook.org/ns/docbook">
                  <replaceable>script</replaceable>
                </command>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>name</replaceable>
                </arg>
                <arg xmlns="http://docbook.org/ns/docbook" choice="opt">
                  <replaceable>args</replaceable>
                </arg>
              </cmdsynopsis>
              <para>where:</para>
              <segmentedlist>
                <seglistitem>
                  <seg>
                    <arg>
                      <replaceable>name</replaceable>
                    </arg>
                  </seg>
                  <seg>The element type name that has ended</seg>
                </seglistitem>
                <seglistitem>
                  <seg>
                    <arg>
                      <replaceable>args</replaceable>
                    </arg>
                  </seg>
                  <seg>Additional information about this element</seg>
                </seglistitem>
              </segmentedlist>
              <para>Additional information about the element takes the form of configuration options.  Possible options are:</para>
              <segmentedlist>
                <seglistitem>
                  <seg>
                    <option>-empty</option>
                    <arg>
                      <replaceable>boolean</replaceable>
                    </arg>
                  </seg>
                  <seg>The empty element syntax was used for this element</seg>
                </seglistitem>
                <seglistitem>
                  <seg>
                    <option>-namespace</option>
                    <arg>
                      <replaceable>uri</replaceable>
                    </arg>
                  </seg>
                  <seg>The element is in the XML namespace associated with the given URI</seg>
                </seglistitem>
              </segmentedlist>
            </listitem>
          </varlistentry>
          <varlistentry>
            <term>
              <option>-elementstartcommand</option>
            </term>
            <listitem>
              <optionsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <option xmlns="http://docbook.org/ns/docbook">-elementstartcommand</option>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>script</replaceable>
                </arg>
              </optionsynopsis>
              <para>Specifies the prefix of a Tcl command to be evaluated when an element start tag is encountered.  The command evaluated is:</para>
              <cmdsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <command xmlns="http://docbook.org/ns/docbook">
                  <replaceable>script</replaceable>
                </command>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>name</replaceable>
                </arg>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>attlist</replaceable>
                </arg>
                <arg xmlns="http://docbook.org/ns/docbook" choice="opt">
                  <replaceable>args</replaceable>
                </arg>
              </cmdsynopsis>
              <para>where:</para>
              <segmentedlist>
                <seglistitem>
                  <seg>
                    <arg>
                      <replaceable>name</replaceable>
                    </arg>
                  </seg>
                  <seg>The element type name that has started</seg>
                </seglistitem>
                <seglistitem>
                  <seg>
                    <arg>
                      <replaceable>attlist</replaceable>
                    </arg>
                  </seg>
                  <seg>A Tcl list containing the attributes for this element.  The list of attributes is formatted as pairs of attribute names and their values.  </seg>
                </seglistitem>
                <seglistitem>
                  <seg>
                    <arg>
                      <replaceable>args</replaceable>
                    </arg>
                  </seg>
                  <seg>Additional information about this element</seg>
                </seglistitem>
              </segmentedlist>
              <para>Additional information about the element takes the form of configuration options.  Possible options are:</para>
              <segmentedlist>
                <seglistitem>
                  <seg>
                    <option>-empty</option>
                    <arg>
                      <replaceable>boolean</replaceable>
                    </arg>
                  </seg>
                  <seg>The empty element syntax was used for this element</seg>
                </seglistitem>
                <seglistitem>
                  <seg>
                    <option>-namespace</option>
                    <arg>
                      <replaceable>uri</replaceable>
                    </arg>
                  </seg>
                  <seg>The element is in the XML namespace associated with the given URI</seg>
                </seglistitem>
                <seglistitem>
                  <seg>
                    <option>-namespacedecls</option>
                    <arg>
                      <replaceable>list</replaceable>
                    </arg>
                  </seg>
                  <seg>The start tag included one or more XML Namespace declarations.  <arg><replaceable>list</replaceable></arg> is a Tcl list giving the namespaces declared.  The list is formatted as pairs of values, the first value is the namespace URI and the second value is the prefix used for the namespace in this document.  A default XML namespace declaration will have an empty string for the prefix.</seg>
                </seglistitem>
              </segmentedlist>
            </listitem>
          </varlistentry>
          <varlistentry>
            <term>
              <option>-encoding</option>
            </term>
            <listitem>
              <optionsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <option xmlns="http://docbook.org/ns/docbook">-encoding</option>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>value</replaceable>
                </arg>
              </optionsynopsis>
              <para>Gives the character encoding of the document.  This option only has an effect before a document is parsed.  The default character encoding is <literal>utf-8</literal>.  If the value <literal>unknown</literal> is given, or any value other than <literal>utf-8</literal>, then the document text is treated as binary data.  If the value is given as <literal>unknown</literal> then the parser will attempt to automatically determine the character encoding of the document (using byte-order-marks, etc).  If any value other than <literal>utf-8</literal> or <literal>unknown</literal> is given then the parser will read the document text using that character encoding.</para>
            </listitem>
          </varlistentry>
          <varlistentry>
            <term>
              <option>-endcdatasectioncommand</option>
            </term>
            <listitem>
              <optionsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <option xmlns="http://docbook.org/ns/docbook">-endcdatasectioncommand</option>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>script</replaceable>
                </arg>
              </optionsynopsis>
              <para>Specifies the prefix of a Tcl command to be evaluated when end of a CDATA section is encountered.  The command is evaluated with no further arguments.</para>
            </listitem>
          </varlistentry>
          <varlistentry>
            <term>
              <option>-enddoctypedeclcommand</option>
            </term>
            <listitem>
              <optionsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <option xmlns="http://docbook.org/ns/docbook">-enddoctypedeclcommand</option>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>script</replaceable>
                </arg>
              </optionsynopsis>
              <para>Specifies the prefix of a Tcl command to be evaluated when end of the document type declaration is encountered.  The command is evaluated with no further arguments.</para>
            </listitem>
          </varlistentry>
          <varlistentry>
            <term>
              <option>-entitydeclcommand</option>
            </term>
            <listitem>
              <optionsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <option xmlns="http://docbook.org/ns/docbook">-entitydeclcommand</option>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>script</replaceable>
                </arg>
              </optionsynopsis>
              <para>Specifies the prefix of a Tcl command to be evaluated when an entity declaration is encountered.  The command evaluated is:</para>
              <cmdsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <command xmlns="http://docbook.org/ns/docbook">
                  <replaceable>script</replaceable>
                </command>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>name</replaceable>
                </arg>
                <arg xmlns="http://docbook.org/ns/docbook" choice="opt" repeat="rep">
                  <replaceable>args</replaceable>
                </arg>
              </cmdsynopsis>
              <para>where:</para>
              <segmentedlist>
                <seglistitem>
                  <seg>
                    <arg>
                      <replaceable>name</replaceable>
                    </arg>
                  </seg>
                  <seg>The name of the entity being declared</seg>
                </seglistitem>
                <seglistitem>
                  <seg>
                    <arg>
                      <replaceable>args</replaceable>
                    </arg>
                  </seg>
                  <seg>Additional information about the entity declaration.  An internal entity shall have a single argument, the replacement text.  An external parsed entity shall have two additional arguments, the public and system indentifiers of the external resource.  An external unparsed entity shall have three additional arguments, the public and system identifiers followed by the notation name.</seg>
                </seglistitem>
              </segmentedlist>
            </listitem>
          </varlistentry>
          <varlistentry>
            <term>
              <option>-entityreferencecommand</option>
            </term>
            <listitem>
              <optionsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <option xmlns="http://docbook.org/ns/docbook">-entityreferencecommand</option>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>script</replaceable>
                </arg>
              </optionsynopsis>
              <para>Specifies the prefix of a Tcl command to be evaluated when an entity reference is encountered.  The command evaluated is:</para>
              <cmdsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <command xmlns="http://docbook.org/ns/docbook">
                  <replaceable>script</replaceable>
                </command>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>name</replaceable>
                </arg>
              </cmdsynopsis>
              <para>where:</para>
              <segmentedlist>
                <seglistitem>
                  <seg>
                    <arg>
                      <replaceable>name</replaceable>
                    </arg>
                  </seg>
                  <seg>The name of the entity being referenced</seg>
                </seglistitem>
              </segmentedlist>
            </listitem>
          </varlistentry>
          <varlistentry>
            <term>
              <option>-errorcommand</option>
            </term>
            <listitem>
              <optionsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <option xmlns="http://docbook.org/ns/docbook">-errorcommand</option>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>script</replaceable>
                </arg>
              </optionsynopsis>
              <para>Specifies the prefix of a Tcl command to be evaluated when a fatal error is detected.  The error may be due to the XML document not being well-formed.  In the case of a validating parser class, the error may also be due to the XML document not obeying validity constraints.  By default, a callback script is provided which causes an error return code, but an application may supply a script which attempts to continue parsing.  The command evaluated is:</para>
              <cmdsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <command xmlns="http://docbook.org/ns/docbook">
                  <replaceable>script</replaceable>
                </command>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>errorcode</replaceable>
                </arg>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>errormsg</replaceable>
                </arg>
              </cmdsynopsis>
              <para>where:</para>
              <segmentedlist>
                <seglistitem>
                  <seg>
                    <arg>
                      <replaceable>errorcode</replaceable>
                    </arg>
                  </seg>
                  <seg>A single word description of the error, intended for use by an application</seg>
                </seglistitem>
                <seglistitem>
                  <seg>
                    <arg>
                      <replaceable>errormsg</replaceable>
                    </arg>
                  </seg>
                  <seg>A human-readable description of the error</seg>
                </seglistitem>
              </segmentedlist>
            </listitem>
          </varlistentry>
          <varlistentry>
            <term>
              <option>-externalentitycommand</option>
            </term>
            <listitem>
              <optionsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <option xmlns="http://docbook.org/ns/docbook">-externalentitycommand</option>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>script</replaceable>
                </arg>
              </optionsynopsis>
              <para>Specifies the prefix of a Tcl command to be evaluated to resolve an external entity reference.  If the parser has been configured to validate the XML document, a default script is supplied that resolves the URI given as the system identifier of the external entity and recursively parses the entity's data.  If the parser has been configured as a non-validating parser, then by default external entities are not resolved.  This option can be used to override the default behaviour.  The command evaluated is:</para>
              <cmdsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <command xmlns="http://docbook.org/ns/docbook">
                  <replaceable>script</replaceable>
                </command>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>name</replaceable>
                </arg>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>baseuri</replaceable>
                </arg>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>uri</replaceable>
                </arg>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>id</replaceable>
                </arg>
              </cmdsynopsis>
              <para>where:</para>
              <segmentedlist>
                <seglistitem>
                  <seg>
                    <arg>
                      <replaceable>name</replaceable>
                    </arg>
                  </seg>
                  <seg>The Tcl command name of the current parser</seg>
                </seglistitem>
                <seglistitem>
                  <seg>
                    <arg>
                      <replaceable>baseuri</replaceable>
                    </arg>
                  </seg>
                  <seg>An absolute URI for the current entity which is to be used to resolve relative URIs</seg>
                </seglistitem>
                <seglistitem>
                  <seg>
                    <arg>
                      <replaceable>uri</replaceable>
                    </arg>
                  </seg>
                  <seg>The system identifier of the external entity, usually a URI</seg>
                </seglistitem>
                <seglistitem>
                  <seg>
                    <arg>
                      <replaceable>id</replaceable>
                    </arg>
                  </seg>
                  <seg>The public identifier of the external entity.  If no public identifier was given in the entity declaration then <arg><replaceable>id</replaceable></arg> will be an empty string.</seg>
                </seglistitem>
              </segmentedlist>
              <para>The return result of the callback script determines the action of the parser.  Note that these codes are interpreted in a different manner to other callbacks.</para>
              <variablelist>
                <varlistentry>
                  <term>
                    <literal>TCL_OK</literal>
                  </term>
                  <listitem>
                    <para>The return result of the callback script is used as the external entity's data.  The URI passed to the callback script is used as the entity's base URI.</para>
                    <para>This is useful to either override the normal loading of an entity's data, or to implement new or alternative URI schemes.  As an example, the script below sets an external entity handler that intercepts "tcl:" URIs and evaluates them as inline Tcl scripts:</para>
                    <informalexample>
                      <programlisting>
package require xml

proc External {name baseuri uri id} {
    switch -glob -- $uri {
	tcl:* {
	    regexp {^tcl:(.*)$} $uri discard script
	    return [uplevel #0 $script]
	}
	default {
	    return -code continue {}
	}
    }
}

set parser [xml::parser -externalentitycommand External]
$parser parse {&lt;!DOCTYPE example [
  &lt;!ENTITY example SYSTEM "tcl:set%20example%20HelloWorld"&gt;
]&gt;
&lt;example&gt;
  &amp;example;
&lt;/example&gt;
}

puts $example
</programlisting>
                    </informalexample>
                    <para>This script will print "HelloWorld" to stdout.</para>
                  </listitem>
                </varlistentry>
                <varlistentry>
                  <term>
                    <literal>TCL_CONTINUE</literal>
                  </term>
                  <listitem>
                    <para>In a normal (non-safe) interpreter, the default external entity handler is used to load the external entity data as per normal operation of the parser.  If the parser is executing in a Safe Tcl interpreter then the entity is not loaded at all.</para>
                    <para>This is useful to interpose on the loading of external entities without interfering with the loading of entities.</para>
                  </listitem>
                </varlistentry>
                <varlistentry>
                  <term>
                    <literal>TCL_BREAK</literal>
                  </term>
                  <listitem>
                    <para>No data is returned for this entity, ie. the entity is ignored.  No error is propagated.</para>
                  </listitem>
                </varlistentry>
                <varlistentry>
                  <term>
                    <literal>TCL_ERROR</literal>
                  </term>
                  <listitem>
                    <para>No data is returned for this entity, ie. the entity is ignored.  A background error is registered, using the result of the callback script.</para>
                  </listitem>
                </varlistentry>
              </variablelist>
            </listitem>
          </varlistentry>
          <varlistentry>
            <term>
              <option>-final</option>
            </term>
            <listitem>
              <optionsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <option xmlns="http://docbook.org/ns/docbook">-final</option>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>boolean</replaceable>
                </arg>
              </optionsynopsis>
              <para>Specifies whether the XML document being parsed is complete.  If the document is to be incrementally parsed then this option will be set to false, and when the last fragment of document is parsed it is set to true.  For example,</para>
              <informalexample>
                <programlisting>
set parser [::xml::parser -final 0]
$parser parse $data1
.
.
.
$parser parse $data2
.
.
.
$parser configure -final 1
$parser parse $finaldata
		</programlisting>
              </informalexample>
            </listitem>
          </varlistentry>
          <varlistentry>
            <term>
              <option>-ignorewhitespace</option>
            </term>
            <listitem>
              <optionsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <option xmlns="http://docbook.org/ns/docbook">-ignorewhitespace</option>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>boolean</replaceable>
                </arg>
              </optionsynopsis>
              <para>If this option is set to true then spans of character data in the XML document which are composed only of white-space (CR, LF, space, tab) will not be reported to the application.  In other words, the data passed to every invocation of the <option>-characterdatacommand</option> script will contain at least one non-white-space character.</para>
            </listitem>
          </varlistentry>
          <varlistentry>
            <term>
              <option>-notationdeclcommand</option>
            </term>
            <listitem>
              <optionsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <option xmlns="http://docbook.org/ns/docbook">-notationdeclcommand</option>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>script</replaceable>
                </arg>
              </optionsynopsis>
              <para>Specifies the prefix of a Tcl command to be evaluated when a notation declaration is encountered.  The command evaluated is:</para>
              <cmdsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <command xmlns="http://docbook.org/ns/docbook">
                  <replaceable>script</replaceable>
                </command>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>name</replaceable>
                </arg>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>uri</replaceable>
                </arg>
              </cmdsynopsis>
              <para>where:</para>
              <segmentedlist>
                <seglistitem>
                  <seg>
                    <arg>
                      <replaceable>name</replaceable>
                    </arg>
                  </seg>
                  <seg>The name of the notation</seg>
                </seglistitem>
                <seglistitem>
                  <seg>
                    <arg>
                      <replaceable>uri</replaceable>
                    </arg>
                  </seg>
                  <seg>An external identifier for the notation, usually a URI.</seg>
                </seglistitem>
              </segmentedlist>
            </listitem>
          </varlistentry>
          <varlistentry>
            <term>
              <option>-notstandalonecommand</option>
            </term>
            <listitem>
              <optionsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <option xmlns="http://docbook.org/ns/docbook">-notstandalonecommand</option>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>script</replaceable>
                </arg>
              </optionsynopsis>
              <para>Specifies the prefix of a Tcl command to be evaluated when the parser determines that the XML document being parsed is not a standalone document.</para>
            </listitem>
          </varlistentry>
          <varlistentry>
            <term>
              <option>-paramentityparsing</option>
            </term>
            <listitem>
              <optionsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <option xmlns="http://docbook.org/ns/docbook">-paramentityparsing</option>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>boolean</replaceable>
                </arg>
              </optionsynopsis>
              <para>Controls whether external parameter entities are parsed.</para>
            </listitem>
          </varlistentry>
          <varlistentry>
            <term>
              <option>-parameterentitydeclcommand</option>
            </term>
            <listitem>
              <optionsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <option xmlns="http://docbook.org/ns/docbook">-parameterentitydeclcommand</option>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>script</replaceable>
                </arg>
              </optionsynopsis>
              <para>Specifies the prefix of a Tcl command to be evaluated when a parameter entity declaration is encountered.  The command evaluated is:</para>
              <cmdsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <command xmlns="http://docbook.org/ns/docbook">
                  <replaceable>script</replaceable>
                </command>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>name</replaceable>
                </arg>
                <arg xmlns="http://docbook.org/ns/docbook" choice="opt">
                  <replaceable>args</replaceable>
                </arg>
              </cmdsynopsis>
              <para>where:</para>
              <segmentedlist>
                <seglistitem>
                  <seg>
                    <arg>
                      <replaceable>name</replaceable>
                    </arg>
                  </seg>
                  <seg>The name of the parameter entity</seg>
                </seglistitem>
                <seglistitem>
                  <seg>
                    <arg choice="opt">
                      <replaceable>args</replaceable>
                    </arg>
                  </seg>
                  <seg>For an internal parameter entity there is only one additional argument, the replacement text.  For external parameter entities there are two additional arguments, the system and public identifiers respectively.</seg>
                </seglistitem>
              </segmentedlist>
            </listitem>
          </varlistentry>
          <varlistentry>
            <term>
              <option>-parser</option>
            </term>
            <listitem>
              <optionsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <option xmlns="http://docbook.org/ns/docbook">-parser</option>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>name</replaceable>
                </arg>
              </optionsynopsis>
              <para>The name of the parser class to instantiate for this parser object.  This option may only be specified when the parser instance is created.</para>
            </listitem>
          </varlistentry>
          <varlistentry>
            <term>
              <option>-processinginstructioncommand</option>
            </term>
            <listitem>
              <optionsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <option xmlns="http://docbook.org/ns/docbook">-processinginstructioncommand</option>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>script</replaceable>
                </arg>
              </optionsynopsis>
              <para>Specifies the prefix of a Tcl command to be evaluated when a processing instruction is encountered.  The command evaluated is:</para>
              <cmdsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <command xmlns="http://docbook.org/ns/docbook">
                  <replaceable>script</replaceable>
                </command>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>target</replaceable>
                </arg>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>data</replaceable>
                </arg>
              </cmdsynopsis>
              <para>where:</para>
              <segmentedlist>
                <seglistitem>
                  <seg>
                    <arg>
                      <replaceable>target</replaceable>
                    </arg>
                  </seg>
                  <seg>The name of the processing instruction target</seg>
                </seglistitem>
                <seglistitem>
                  <seg>
                    <arg>
                      <replaceable>data</replaceable>
                    </arg>
                  </seg>
                  <seg>Remaining data from the processing instruction</seg>
                </seglistitem>
              </segmentedlist>
            </listitem>
          </varlistentry>
          <varlistentry>
            <term>
              <option>-reportempty</option>
            </term>
            <listitem>
              <optionsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <option xmlns="http://docbook.org/ns/docbook">-reportempty</option>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>boolean</replaceable>
                </arg>
              </optionsynopsis>
              <para>If this option is enabled then when an element is encountered that uses the special empty element syntax, additional arguments are appended to the <option>-elementstartcommand</option> and <option>-elementendcommand</option> callbacks.  The arguments <arg>-empty 1</arg> are appended.  For example:</para>
              <cmdsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <command xmlns="http://docbook.org/ns/docbook">
                  <replaceable>script</replaceable>
                </command>
                <option xmlns="http://docbook.org/ns/docbook">-empty</option>
                <arg xmlns="http://docbook.org/ns/docbook">1</arg>
              </cmdsynopsis>
            </listitem>
          </varlistentry>
          <varlistentry>
            <term>
              <option>-startcdatasectioncommand</option>
            </term>
            <listitem>
              <optionsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <option xmlns="http://docbook.org/ns/docbook">-startcdatasectioncommand</option>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>script</replaceable>
                </arg>
              </optionsynopsis>
              <para>Specifies the prefix of a Tcl command to be evaluated when the start of a CDATA section section is encountered.  No arguments are appended to the script.</para>
            </listitem>
          </varlistentry>
          <varlistentry>
            <term>
              <option>-startdoctypedeclcommand</option>
            </term>
            <listitem>
              <optionsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <option xmlns="http://docbook.org/ns/docbook">-startdoctypedeclcommand</option>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>script</replaceable>
                </arg>
              </optionsynopsis>
              <para>Specifies the prefix of a Tcl command to be evaluated at the start of a document type declaration.  No arguments are appended to the script.</para>
            </listitem>
          </varlistentry>
          <varlistentry>
            <term>
              <option>-unknownencodingcommand</option>
            </term>
            <listitem>
              <optionsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <option xmlns="http://docbook.org/ns/docbook">-unknownencodingcommand</option>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>script</replaceable>
                </arg>
              </optionsynopsis>
              <para>Specifies the prefix of a Tcl command to be evaluated when a character is encountered with an unknown encoding.  This option has not been implemented.</para>
            </listitem>
          </varlistentry>
          <varlistentry>
            <term>
              <option>-unparsedentitydeclcommand</option>
            </term>
            <listitem>
              <optionsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <option xmlns="http://docbook.org/ns/docbook">-unparsedentitydeclcommand</option>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>script</replaceable>
                </arg>
              </optionsynopsis>
              <para>Specifies the prefix of a Tcl command to be evaluated when a declaration is encountered for an unparsed entity.  The command evaluated is:</para>
              <cmdsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <command xmlns="http://docbook.org/ns/docbook">
                  <replaceable>script</replaceable>
                </command>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>system</replaceable>
                </arg>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>public</replaceable>
                </arg>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>notation</replaceable>
                </arg>
              </cmdsynopsis>
              <para>where:</para>
              <segmentedlist>
                <seglistitem>
                  <seg>
                    <arg>
                      <replaceable>system</replaceable>
                    </arg>
                  </seg>
                  <seg>The system identifier of the external entity, usually a URI</seg>
                </seglistitem>
                <seglistitem>
                  <seg>
                    <arg>
                      <replaceable>public</replaceable>
                    </arg>
                  </seg>
                  <seg>The public identifier of the external entity</seg>
                </seglistitem>
                <seglistitem>
                  <seg>
                    <arg>
                      <replaceable>notation</replaceable>
                    </arg>
                  </seg>
                  <seg>The name of the notation for the external entity</seg>
                </seglistitem>
              </segmentedlist>
            </listitem>
          </varlistentry>
          <varlistentry>
            <term>
              <option>-validate</option>
            </term>
            <listitem>
              <optionsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <option xmlns="http://docbook.org/ns/docbook">-validate</option>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>boolean</replaceable>
                </arg>
              </optionsynopsis>
              <para>Enables validation of the XML document to be parsed.  Any changes to this option are ignored after an XML document has started to be parsed, but the option may be changed after a reset.</para>
            </listitem>
          </varlistentry>
          <varlistentry>
            <term>
              <option>-warningcommand</option>
            </term>
            <listitem>
              <optionsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <option xmlns="http://docbook.org/ns/docbook">-warningcommand</option>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>script</replaceable>
                </arg>
              </optionsynopsis>
              <para>Specifies the prefix of a Tcl command to be evaluated when a warning condition is detected.  A warning condition is where the XML document has not been authored correctly, but is still well-formed and may be valid.  For example, the special empty element syntax may be used for an element which has not been declared to have empty content.  By default, a callback script is provided which silently ignores the warning.  The command evaluated is:</para>
              <cmdsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <command xmlns="http://docbook.org/ns/docbook">
                  <replaceable>script</replaceable>
                </command>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>warningcode</replaceable>
                </arg>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>warningmsg</replaceable>
                </arg>
              </cmdsynopsis>
              <para>where:</para>
              <segmentedlist>
                <seglistitem>
                  <seg>
                    <arg>
                      <replaceable>warningcode</replaceable>
                    </arg>
                  </seg>
                  <seg>A single word description of the warning, intended for use by an application</seg>
                </seglistitem>
                <seglistitem>
                  <seg>
                    <arg>
                      <replaceable>wanringmsg</replaceable>
                    </arg>
                  </seg>
                  <seg>A human-readable description of the warning</seg>
                </seglistitem>
              </segmentedlist>
            </listitem>
          </varlistentry>
          <varlistentry>
            <term>
              <option>-xmldeclcommand</option>
            </term>
            <listitem>
              <optionsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <option xmlns="http://docbook.org/ns/docbook">-xmldeclcommand</option>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>script</replaceable>
                </arg>
              </optionsynopsis>
              <para>Specifies the prefix of a Tcl command to be evaluated when the XML declaration is encountered.  The command evaluated is:</para>
              <cmdsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <command xmlns="http://docbook.org/ns/docbook">
                  <replaceable>script</replaceable>
                </command>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>version</replaceable>
                </arg>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>encoding</replaceable>
                </arg>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>standalone</replaceable>
                </arg>
              </cmdsynopsis>
              <para>where:</para>
              <segmentedlist>
                <seglistitem>
                  <seg>
                    <arg>
                      <replaceable>version</replaceable>
                    </arg>
                  </seg>
                  <seg>The version number of the XML specification to which this document purports to conform</seg>
                </seglistitem>
                <seglistitem>
                  <seg>
                    <arg>
                      <replaceable>encoding</replaceable>
                    </arg>
                  </seg>
                  <seg>The character encoding of the document</seg>
                </seglistitem>
                <seglistitem>
                  <seg>
                    <arg>
                      <replaceable>standalone</replaceable>
                    </arg>
                  </seg>
                  <seg>A boolean declaring whether the document is standalone</seg>
                </seglistitem>
              </segmentedlist>
            </listitem>
          </varlistentry>
        </variablelist>
      </refsect3>
      <refsect3>
        <d:info xmlns:d="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:tcl="http://tclxml.sourceforge.net/doc">
          <d:title>Parser Command</d:title>
        </d:info>
        <para>The <command xmlns="http://tclxml.sourceforge.net/doc">::xml::parser</command> command creates a new Tcl command with the same name as the parser.  This command may be used to invoke various operations on the parser object.  It has the following general form:</para>
        <cmdsynopsis xmlns="http://tclxml.sourceforge.net/doc">
          <command xmlns="http://docbook.org/ns/docbook" role="subject">
            <replaceable>name</replaceable>
          </command>
          <option xmlns="http://docbook.org/ns/docbook">
            <replaceable>option</replaceable>
          </option>
          <arg xmlns="http://docbook.org/ns/docbook" rep="repeat">
            <replaceable>arg</replaceable>
          </arg>
        </cmdsynopsis>
        <para><option><replaceable>option</replaceable></option> and the <arg rep="repeat"><replaceable>arg</replaceable></arg> determine the exact behaviour of the command.  The following commands are possible for parser objects:</para>
        <variablelist>
          <varlistentry>
            <term>
              <option>cget</option>
            </term>
            <listitem>
              <cmdsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <option xmlns="http://docbook.org/ns/docbook">cget</option>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>-option</replaceable>
                </arg>
              </cmdsynopsis>
              <para>Returns the current value of the configuration option given by <option><replaceable>option</replaceable></option>.  <option><replaceable>Option</replaceable></option> may have any of the values accepted by the parser object.</para>
            </listitem>
          </varlistentry>
          <varlistentry>
            <term>
              <option>configure</option>
            </term>
            <listitem>
              <cmdsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <option xmlns="http://docbook.org/ns/docbook">configure</option>
                <group xmlns="http://docbook.org/ns/docbook" rep="repeat">
                  <arg>
                    <replaceable>-option</replaceable>
                  </arg>
                  <arg>
                    <replaceable>value</replaceable>
                  </arg>
                </group>
              </cmdsynopsis>
              <para>Modify the configuration options of the parser object.  <option><replaceable>Option</replaceable></option> may have any of the values accepted by the parser object.</para>
            </listitem>
          </varlistentry>
          <varlistentry>
            <term>
              <option>entityparser</option>
            </term>
            <listitem>
              <cmdsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <option xmlns="http://docbook.org/ns/docbook">entityparser</option>
                <group xmlns="http://docbook.org/ns/docbook" rep="repeat">
                  <arg>
                    <replaceable>option</replaceable>
                  </arg>
                  <arg>
                    <replaceable>value</replaceable>
                  </arg>
                </group>
              </cmdsynopsis>
              <para>Creates a new parser object.  The new object inherits the same configuration options as the parent parser object, but is able to parse XML data in a parsed entity.  The option <option>-dtdsubset</option> allows markup declarations to be treated as being in the internal or external DTD subset.</para>
            </listitem>
          </varlistentry>
          <varlistentry>
            <term>
              <option>free</option>
            </term>
            <listitem>
              <cmdsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <option xmlns="http://docbook.org/ns/docbook">free</option>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>name</replaceable>
                </arg>
              </cmdsynopsis>
              <para>Frees all resources associated with the parser object.  The object is not usable after this command has been invoked.</para>
            </listitem>
          </varlistentry>
          <varlistentry>
            <term>
              <option>get</option>
            </term>
            <listitem>
              <cmdsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <option xmlns="http://docbook.org/ns/docbook">get</option>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>name</replaceable>
                </arg>
                <arg xmlns="http://docbook.org/ns/docbook" rep="repeat" choice="opt">args</arg>
              </cmdsynopsis>
              <para>Returns information about the XML document being parsed.  Each parser class provides different information, see the documentation for the parser class.</para>
            </listitem>
          </varlistentry>
          <varlistentry>
            <term>
              <option>parse</option>
            </term>
            <listitem>
              <cmdsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <option xmlns="http://docbook.org/ns/docbook">parse</option>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>xml</replaceable>
                </arg>
                <arg xmlns="http://docbook.org/ns/docbook" rep="repeat" choice="opt">args</arg>
              </cmdsynopsis>
              <para>Parses the XML document.  The usual desired effect is for various application callbacks to be evaluated.  Other functions will also be performed by the parser class, at the very least this includes checking the XML document for well-formedness.</para>
            </listitem>
          </varlistentry>
          <varlistentry>
            <term>
              <option>reset</option>
            </term>
            <listitem>
              <cmdsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <option xmlns="http://docbook.org/ns/docbook">reset</option>
              </cmdsynopsis>
              <para>Initialises the parser object in preparation for parsing a new XML document.</para>
            </listitem>
          </varlistentry>
        </variablelist>
      </refsect3>
    </refsect2>
  </refsect1>
  <refsect1>
    <d:info xmlns:d="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:tcl="http://tclxml.sourceforge.net/doc">
      <d:title>Callback Return Codes</d:title>
    </d:info>
    <para>Every callback script evaluated by a parser may return a return code other than <arg>TCL_OK</arg>.  Return codes are interpreted as follows:</para>
    <segmentedlist>
      <seglistitem>
        <seg>break</seg>
        <seg>Suppresses invocation of all further callback scripts.  The <option>parse</option> method returns the <arg>TCL_OK</arg> return code.</seg>
      </seglistitem>
      <seglistitem>
        <seg>continue</seg>
        <seg>Suppresses invocation of further callback scripts until the current element has finished.</seg>
      </seglistitem>
      <seglistitem>
        <seg>error</seg>
        <seg>Suppresses invocation of all further callback scripts.  The <option>parse</option> method also returns the <arg>TCL_ERROR</arg> return code.</seg>
      </seglistitem>
      <seglistitem>
        <seg>default</seg>
        <seg>Any other return code suppresses invocation of all further callback scripts.  The <option>parse</option> method returns the same return code.</seg>
      </seglistitem>
    </segmentedlist>
  </refsect1>
  <refsect1>
    <d:info xmlns:d="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:tcl="http://tclxml.sourceforge.net/doc">
      <d:title>Error Messages</d:title>
    </d:info>
    <para>If an error or warning condition is detected then an error message is returned.  These messages are structured as a Tcl list, as described below:</para>
    <informalexample>
      <programlisting>{domain level code node line message int1 int2 string1 string2 string3}</programlisting>
    </informalexample>
    <variablelist>
      <varlistentry>
        <term>
          <literal>domain</literal>
        </term>
        <listitem>
          <para>A code for the subsystem that detected the error.</para>
        </listitem>
      </varlistentry>
      <varlistentry>
        <term>
          <literal>level</literal>
        </term>
        <listitem>
          <para>Severity level of the problem.</para>
        </listitem>
      </varlistentry>
      <varlistentry>
        <term>
          <literal>code</literal>
        </term>
        <listitem>
          <para>A one word string describing the error.</para>
        </listitem>
      </varlistentry>
      <varlistentry>
        <term>
          <literal>node</literal>
        </term>
        <listitem>
          <para>If available, the token of the DOM node associated with the problem.</para>
        </listitem>
      </varlistentry>
      <varlistentry>
        <term>
          <literal>line</literal>
        </term>
        <listitem>
          <para>If known, the line number in the source XML document where the problem was detected.</para>
        </listitem>
      </varlistentry>
      <varlistentry>
        <term>
          <literal>message</literal>
        </term>
        <listitem>
          <para>A human-readable description of the problem.</para>
        </listitem>
      </varlistentry>
      <varlistentry>
        <term>
          <literal>int1</literal>
        </term>
        <listitem>
          <para>Additional integer data.  For the parser domain, this is usually the column number where the problem was detected.</para>
        </listitem>
      </varlistentry>
      <varlistentry>
        <term>
          <literal>int2</literal>
        </term>
        <listitem>
          <para>Additional integer data.</para>
        </listitem>
      </varlistentry>
      <varlistentry>
        <term>
          <literal>string1</literal>
        </term>
        <listitem>
          <para>Additional string data.</para>
        </listitem>
      </varlistentry>
      <varlistentry>
        <term>
          <literal>string2</literal>
        </term>
        <listitem>
          <para>Additional string data.</para>
        </listitem>
      </varlistentry>
      <varlistentry>
        <term>
          <literal>string3</literal>
        </term>
        <listitem>
          <para>Additional string data.</para>
        </listitem>
      </varlistentry>
    </variablelist>
  </refsect1>
  <refsect1>
    <d:info xmlns:d="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:tcl="http://tclxml.sourceforge.net/doc">
      <d:title>Application Examples</d:title>
    </d:info>
    <para>This script outputs the character data of an XML document read from stdin.</para>
    <informalexample>
      <programlisting>
package require xml

proc cdata {data args} {
    puts -nonewline $data
}

set parser [::xml::parser -characterdatacommand cdata]
$parser parse [read stdin]
      </programlisting>
    </informalexample>
    <para>This script counts the number of elements in an XML document read from stdin.</para>
    <informalexample>
      <programlisting>
package require xml

proc EStart {varName name attlist args} {
    upvar #0 $varName var
    incr var
}

set count 0
set parser [::xml::parser -elementstartcommand [list EStart count]]
$parser parse [read stdin]
puts "The XML document contains $count elements"
      </programlisting>
    </informalexample>
  </refsect1>
  <refsect1>
    <d:info xmlns:d="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:tcl="http://tclxml.sourceforge.net/doc">
      <d:title>Safe XML</d:title>
    </d:info>
    <para>TclXML/Tcl and TclXML/libxml2 may be used in a Safe Tcl interpreter.  When a document is parsed in a Safe Tcl interpreter, any attempt by the XML document to load an external entity is handled by the -externalentitycommand callback.  This callback is evaluated in the context of the safe interpreter and therefore is subject to the security policy in force for that interpreter.  The default entity loader will not be invoked, even if the callback script returns a <literal>TCL_CONTINUE</literal> code.</para>
    <para>See the description of the -externalentitycommand for further details.</para>
  </refsect1>
  <refsect1>
    <d:info xmlns:d="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:tcl="http://tclxml.sourceforge.net/doc">
      <d:title>Parser Classes</d:title>
    </d:info>
    <para>This section will discuss how a parser class is implemented.</para>
    <refsect2>
      <d:info xmlns:d="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:tcl="http://tclxml.sourceforge.net/doc">
        <d:title>Tcl Parser Class</d:title>
      </d:info>
      <para>The pure-Tcl parser class requires no compilation - it is a collection of Tcl scripts.  This parser implementation is non-validating, ie. it can only check well-formedness in a document.  However, by enabling the <option>-validate</option> option it will read the document's DTD and resolve external entities.  This parser class is referred to as TclXML/tcl.</para>
      <para>This parser implementation aims to implement XML v1.0 and supports XML Namespaces.</para>
      <para>Generally the parser produces XML Infoset information items.  That is, it gives the application a slightly higher-level view than the raw XML syntax.  For example, it does not report CDATA Sections.</para>
      <para>TclXML/tcl is not able to handle character encodings other than UTF-8.</para>
    </refsect2>
    <refsect2>
      <d:info xmlns:d="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:tcl="http://tclxml.sourceforge.net/doc">
        <d:title>libxml2 Parser Class</d:title>
      </d:info>
      <para>The libxml2 parser class provides a Tcl interface to the libxml2 XML parser library.  This parser class is referred to as TclXML/libxml2.</para>
      <para>When the package is loaded the variable <literal>::xml::libxml2::libxml2version</literal> is set to the version number of the libxml2 library being used.</para>
      <para>On MS Windows, it is necessary to load the generic XML package first, and then the TclXML/libxml2 package.  For example,</para>
      <informalexample>
        <programlisting>
package require xml
package require xml::libxml2
</programlisting>
      </informalexample>
      <refsect3>
        <d:info xmlns:d="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:tcl="http://tclxml.sourceforge.net/doc">
          <d:title>get Method</d:title>
        </d:info>
        <para>TclXML/libxml2 provides the following arguments to the get method:</para>
        <variablelist>
          <varlistentry>
            <term>
              <arg>document</arg>
            </term>
            <listitem>
              <para>Returns the parsed document object.  libxml2 builds an in-memory data structure of the XML document it parses (a DOM tree).  This method returns a handle (or token) for that structure.</para>
              <para>TclXML/libxml2 manages the document object as a Tcl object.  See the <option>-keep</option> for further information.</para>
            </listitem>
          </varlistentry>
        </variablelist>
      </refsect3>
      <refsect3>
        <d:info xmlns:d="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:tcl="http://tclxml.sourceforge.net/doc">
          <d:title>Additional Options</d:title>
        </d:info>
        <variablelist>
          <varlistentry>
            <term>
              <option>-keep</option>
            </term>
            <listitem>
              <optionsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <option xmlns="http://docbook.org/ns/docbook">-keep</option>
                <arg xmlns="http://docbook.org/ns/docbook">normal | implicit</arg>
              </optionsynopsis>
              <para>Controls how the TclXML/libxml2 packages manages the document object.  The default value is <literal>implicit</literal>; the document is destroyed when the Tcl Object's internal representation is freed.  If the option is given the value <literal>normal</literal> then the document must be explicit destroyed.  The only way to explicitly destroy the document is by using the C API.</para>
            </listitem>
          </varlistentry>
          <varlistentry>
            <term>
              <option>-retainpath</option>
            </term>
            <listitem>
              <optionsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <option xmlns="http://docbook.org/ns/docbook">-retainpath</option>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>xpath</replaceable>
                </arg>
              </optionsynopsis>
              <para>The given XPath location path specifies which part of the document is to be kept after the parsing operation has completed.  By default, all document data is discard after it has been parsed.</para>
            </listitem>
          </varlistentry>
          <varlistentry>
            <term>
              <option>-retainpathns</option>
            </term>
            <listitem>
              <optionsynopsis xmlns="http://tclxml.sourceforge.net/doc">
                <option xmlns="http://docbook.org/ns/docbook">-retainpathns</option>
                <arg xmlns="http://docbook.org/ns/docbook">
                  <replaceable>prefix ns ...</replaceable>
                </arg>
              </optionsynopsis>
              <para>The value of this option is a list of pairs of XML Namespace prefixes and their corresponding namespace URIs.  These are used by the XPath location path given in the <arg>-retainpath</arg> option.</para>
            </listitem>
          </varlistentry>
        </variablelist>
      </refsect3>
      <refsect3>
        <d:info xmlns:d="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:tcl="http://tclxml.sourceforge.net/doc">
          <d:title>Limitations</d:title>
        </d:info>
        <para>The libxml2 parser classes has the following limitations:</para>
        <itemizedlist>
          <listitem>
            <para><option>-reportempty</option> has no effect.  libxml2 does not report empty element syntax.</para>
          </listitem>
          <listitem>
            <para>Incremental (push) parsing, ie. <arg><option>-final</option>&#xa0;<literal>0</literal></arg> is not supported.</para>
          </listitem>
          <listitem>
            <para>TclXML/libxml2 does not provide (DTD) validation, (WXS) schema validation or Relax NG validation, although the libxml2 library does provide those functions.  These functions are provided by the TclDOM/libxml2 package, but only in a "posteriori" fashion (ie. only after the document has been parsed).</para>
          </listitem>
          <listitem>
            <para>libxml2 supports XML Namespaces.  The use of XML Namespaces can be queried, but the <emphasis>declaration</emphasis> of a XML Namespace is not reported.</para>
          </listitem>
        </itemizedlist>
      </refsect3>
    </refsect2>
  </refsect1>
  <refsect1>
    <d:info xmlns:d="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:tcl="http://tclxml.sourceforge.net/doc">
      <d:title>Keywords</d:title>
    </d:info>
    <keywordset>
      <keyword>XML</keyword>
      <keyword>parse</keyword>
    </keywordset>
  </refsect1>
</refentry>
