{"id":16874190,"url":"https://github.com/olebole/tclxml","last_synced_at":"2025-03-18T22:36:30.703Z","repository":{"id":49880104,"uuid":"103762422","full_name":"olebole/tclxml","owner":"olebole","description":"Derived version of the TclXML/TclDOM,TclXSLT, tclxml only, Tcl/Tk 8.5/8.6 TEA compatible.","archived":false,"fork":false,"pushed_at":"2021-06-09T06:17:30.000Z","size":422,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-25T00:13:46.271Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/olebole.png","metadata":{"files":{"readme":"README.html","changelog":"ChangeLog","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-09-16T15:25:20.000Z","updated_at":"2021-06-09T06:17:34.000Z","dependencies_parsed_at":"2022-09-17T17:02:30.745Z","dependency_job_id":null,"html_url":"https://github.com/olebole/tclxml","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olebole%2Ftclxml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olebole%2Ftclxml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olebole%2Ftclxml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olebole%2Ftclxml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/olebole","download_url":"https://codeload.github.com/olebole/tclxml/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244320123,"owners_count":20434088,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-13T15:30:19.132Z","updated_at":"2025-03-18T22:36:30.678Z","avatar_url":"https://github.com/olebole.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003chtml\u003e\n\u003chead\u003e\n\u003cmeta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"\u003e\n\u003ctitle\u003eXML Support For Tcl\u003c/title\u003e\n\u003clink rel=\"stylesheet\" href=\"tclxml.css\"\u003e\n\u003c/head\u003e\n\u003cbody\u003e\u003cdiv class=\"article\"\u003e\n\u003ch1 class=\"title\"\u003e\u003ca name=\"id18406\"\u003eXML Support For Tcl\u003c/a\u003e\u003c/h1\u003e\n\u003ch3\u003eTclXML, TclDOM and TclXSLT\u003c/h3\u003e\n\u003ch2\u003eContents\u003c/h2\u003e\n\u003cul\u003e\n\u003cli\u003e\u003ca href=\"#id18498\"\u003eTclXML\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"#id18546\"\u003eTclDOM\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"#id18594\"\u003eTclXSLT\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\n\u003ca href=\"#id18619\"\u003eInstallation\u003c/a\u003e\u003cul\u003e\n\u003cli\u003e\u003ca href=\"#id18633\"\u003eDependencies\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"#id18747\"\u003ePure-Tcl Installation\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\n\u003ca href=\"#id18776\"\u003eCompiled Installation\u003c/a\u003e\u003cul\u003e\n\u003cli\u003e\u003ca href=\"#id18786\"\u003eUnix/Linux\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"#id18948\"\u003eWindows (MSYS/MINGW)\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"#id18987\"\u003eWindows (NMAKE/VC++ 6.0)\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"#id19109\"\u003eMacintosh OS X\u003c/a\u003e\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003ca href=\"#id19193\"\u003eUsage\u003c/a\u003e\u003cul\u003e\n\u003cli\u003e\u003ca href=\"#id19216\"\u003eParsing XML, Streaming\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"#id19244\"\u003eParsing XML with DOM\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"#id19268\"\u003eTransforming XML with XSLT\u003c/a\u003e\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"#id19306\"\u003eXPath\u003c/a\u003e\u003c/li\u003e\n\u003c/ul\u003e\n\u003ch3\u003eTclXML, TclDOM and TclXSLT\u003c/h3\u003e\n\u003cp\u003eThis package provides XML parsers, DOM scripting and XSL Transformations for \u003ca href=\"http://www.tcl.tk\"\u003eTcl\u003c/a\u003e. In previous distributions, these features were supplied as separate packages. Now they have been combined into a single package to make installation easier.\u003c/p\u003e\n\u003cp\u003eContact \u003ca href=\"mailto:Steve.Ball@explain.com.au\"\u003eSteve Ball\u003c/a\u003e for information about this release.\u003c/p\u003e\n\u003cdiv class=\"section\"\u003e\n\u003ch3\u003e\n\u003ca name=\"id18498\"\u003e\u003c/a\u003eTclXML\u003c/h3\u003e\n\u003cp\u003eTclXML provides a streaming parser for XML documents. This is the lowest-level interface for processing XML documents in Tcl. The package has a generic front-end interface with plugin parser implementations.  A number of parser implementations or wrappers are provided:\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003e\u003cp\u003eGnome libxml2 library.  This package is known as TclXML/libxml2.\u003c/p\u003e\u003c/li\u003e\n\u003cli\u003e\u003cp\u003eA generic Tcl implementation (which does not require compilation).  This package is known as TclXML/tcl.\u003c/p\u003e\u003c/li\u003e\n\u003c/ul\u003e\n\u003cp\u003eBoth of these implementations may be installed at the same time. See \u003ca href=\"doc/tclxml.html\"\u003ethe manual page\u003c/a\u003e for more information.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv class=\"section\"\u003e\n\u003ch3\u003e\n\u003ca name=\"id18546\"\u003e\u003c/a\u003eTclDOM\u003c/h3\u003e\n\u003cp\u003eTclDOM provides a tree view for XML documents. This is usually the best interface for scripting XML documents using Tcl. The package has two implementations:\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003e\u003cp\u003eGnome libxml2 library.  This package is known as TclDOM/libxml2.\u003c/p\u003e\u003c/li\u003e\n\u003cli\u003e\u003cp\u003eA generic Tcl implementation (which does not require compilation).  This package is known as TclDOM/tcl.\u003c/p\u003e\u003c/li\u003e\n\u003c/ul\u003e\n\u003cp\u003eOnly one of these will be installed.\u003c/p\u003e\n\u003cp\u003eSee \u003ca href=\"doc/tcldom.html\"\u003ethe manual page\u003c/a\u003e for more information.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv class=\"section\"\u003e\n\u003ch3\u003e\n\u003ca name=\"id18594\"\u003e\u003c/a\u003eTclXSLT\u003c/h3\u003e\n\u003cp\u003eTclXSLT provides a method to invoke XSL Transformations upon XML documents. This package is a wrapper for the libxslt library.\u003c/p\u003e\n\u003cp\u003eSee \u003ca href=\"doc/tclxslt.html\"\u003ethe manual page\u003c/a\u003e for more information.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv class=\"section\"\u003e\n\u003ch3\u003e\n\u003ca name=\"id18619\"\u003e\u003c/a\u003eInstallation\u003c/h3\u003e\n\u003cdiv class=\"section\"\u003e\n\u003ch4\u003e\n\u003ca name=\"id18633\"\u003e\u003c/a\u003eDependencies\u003c/h4\u003e\n\u003cdl\u003e\n\u003cspan class=\"term\"\u003eTcllib\u003c/span\u003e\u003cdd\u003e\n\u003cp\u003e\u003ca href=\"http://www.tcl.tk/software/tcllib/\"\u003ehttp://www.tcl.tk/software/tcllib/\u003c/a\u003e\u003c/p\u003e\n\u003cp\u003eIn order for the Tcl-only parser to resolve external entities, the tcllib package must be installed.\u003c/p\u003e\n\u003cp\u003eBe sure to get a version which includes the \u003ctt\u003euri\u003c/tt\u003e package.  Version 1.11 or better is recommended.\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003e\u003cp\u003e\u003ca href=\"ftp://prdownloads.sf.net/tcllib/tcllib-1.11.tar.gz\"\u003eGZip'd tarball\u003c/a\u003e\u003c/p\u003e\u003c/li\u003e\n\u003cli\u003e\u003cp\u003e\u003ca href=\"ftp://prdownloads.sf.net/tcllib/tcllib-1.11.zip\"\u003eZIP file\u003c/a\u003e\u003c/p\u003e\u003c/li\u003e\n\u003c/ul\u003e\n\u003cp\u003eThe latest CVS snapshot may be found at \u003ca href=\"http://sourceforge.net/projects/tcllib\"\u003ethe SourceForge project page\u003c/a\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cspan class=\"term\"\u003elibxml2\u003c/span\u003e\u003cdd\u003e\n\u003cp\u003elibxml2 is required for the compiled version of the TclXML/libxml2 package.  libiconv may also be required.\u003c/p\u003e\n\u003cp\u003eThe source code for libxml2 and libiconv is \u003cem\u003enot\u003c/em\u003e supplied with this package.  Download libxml2 from \u003ca href=\"http://xmlsoft.org/\"\u003exmlsoft.org\u003c/a\u003e separately. libiconv may also be required; download from a GNU mirror site.\u003c/p\u003e\n\u003cp\u003eVersion 2.7.2 (or better) is recommended.\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\u003c/div\u003e\n\u003cdiv class=\"section\"\u003e\n\u003ch4\u003e\n\u003ca name=\"id18747\"\u003e\u003c/a\u003ePure-Tcl Installation\u003c/h4\u003e\n\u003ch3\u003eno compilation required\u003c/h3\u003e\n\u003cp\u003eRun the configure script and invoke the command:\u003c/p\u003e\n\u003cdiv class=\"informalexample\"\u003e\u003cpre\u003e\u003cstrong\u003emake install\u003c/strong\u003e\u003c/pre\u003e\u003c/div\u003e\n\u003cp\u003eIf the pure-Tcl parser is good enough for you, then read no further.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv class=\"section\"\u003e\n\u003ch4\u003e\n\u003ca name=\"id18776\"\u003e\u003c/a\u003eCompiled Installation\u003c/h4\u003e\n\u003cdiv class=\"section\"\u003e\n\u003ch5\u003e\n\u003ca name=\"id18786\"\u003e\u003c/a\u003eUnix/Linux\u003c/h5\u003e\n\u003cp\u003eYou must have Tcl/Tk version 8.2 or better installed on your system.  Tcl/Tk 8.3 or better is recommended.\u003c/p\u003e\n\u003col\u003e\n\u003cli\u003e\u003cp\u003eMake sure you have Tcllib 1.11 (or better) installed.  Tcllib is still required, even for the compiled parser.\u003c/p\u003e\u003c/li\u003e\n\u003cli\u003e\u003cp\u003eIf you wish to use TclXML/libxml2, make sure libxml2-2.7.2 (or better) is installed.\u003c/p\u003e\u003c/li\u003e\n\u003cli\u003e\u003cp\u003eUnpack the TclXML distribution and \u003cstrong\u003ecd\u003c/strong\u003e into the \u003ctt\u003etclxml-3.2\u003c/tt\u003e directory.\u003c/p\u003e\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003eRun the \u003ctt\u003econfigure\u003c/tt\u003e script, with the \u003cspan class=\"arg\"\u003e--prefix\u003c/span\u003e and  \u003cspan class=\"arg\"\u003e--enable-threads\u003c/span\u003e switches (the latter only if Tcl has been built with threads enabled). Use the  \u003cspan class=\"arg\"\u003e--with-xml2-config\u003c/span\u003e switch to specify the location of the libxml2 configuration script, \u003ctt\u003exml2Conf.sh\u003c/tt\u003e. Similarly, use the  \u003cspan class=\"arg\"\u003e--with-xslt-config\u003c/span\u003e if necessary.\u003c/p\u003e\n\u003cp\u003eTclXML/libxml2 may be configured to statically link the libxml2 and libxslt libraries to the libtclxml.so shared library. This is advantageous when using TclXML/libxml2 in a StarKit. To statically link the libraries use the \u003cspan class=\"arg\"\u003e--with-xml-static\u003c/span\u003e switch.\u003c/p\u003e\n\u003cp\u003eFor example, on my system I have Tcl 8.5 installed in \u003ctt\u003e/usr/local/tcl8.5\u003c/tt\u003e and libxm2 installed in \u003ctt\u003e/usr/local/gnome\u003c/tt\u003e. I also need to statically link the libraries. Therefore I would use the command:\u003c/p\u003e\n\u003cdiv class=\"programlisting\"\u003e\u003cpre\u003e./configure --prefix=/usr/local/tcl8.5 --enable-threads --with-xml2-config=/usr/local/gnome/bin/xml2Conf.sh --with-xml-static=1\u003c/pre\u003e\u003c/div\u003e\n\u003c/li\u003e\n\u003cli\u003e\u003cdiv class=\"programlisting\"\u003e\u003cpre\u003emake\u003c/pre\u003e\u003c/div\u003e\u003c/li\u003e\n\u003cli\u003e\u003cdiv class=\"note\"\u003eDon't test the package using \u003cspan class=\"literal\"\u003emake test\u003c/span\u003e until all of the packages are installed (it is a current deficiency of the build system that the package cannot be tested before installation - we hope to fix this soon!).\u003c/div\u003e\u003c/li\u003e\n\u003cli\u003e\n\u003cdiv class=\"programlisting\"\u003e\u003cpre\u003emake install\u003c/pre\u003e\u003c/div\u003e\n\u003cp\u003eYou may need to do this as root, depending on your installation.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\u003cdiv class=\"programlisting\"\u003e\u003cpre\u003emake test\u003c/pre\u003e\u003c/div\u003e\u003c/li\u003e\n\u003cli\u003e\u003cdiv class=\"programlisting\"\u003e\u003cpre\u003emake doc\u003c/pre\u003e\u003c/div\u003e\u003c/li\u003e\n\u003cli\u003e\u003cdiv class=\"programlisting\"\u003e\u003cpre\u003emake install-doc\u003c/pre\u003e\u003c/div\u003e\u003c/li\u003e\n\u003c/ol\u003e\n\u003c/div\u003e\n\u003cdiv class=\"section\"\u003e\n\u003ch5\u003e\n\u003ca name=\"id18948\"\u003e\u003c/a\u003eWindows (MSYS/MINGW)\u003c/h5\u003e\n\u003cdiv class=\"note\"\u003e[Advice:  ActiveTcl includes binaries for TclXML.]\u003c/div\u003e\n\u003cp\u003eYou must have Tcl/Tk version 8.2 or better installed on your system.  Tcl/Tk 8.5.5 or better is recommended.\u003c/p\u003e\n\u003cp\u003eBefore starting, download the binaries for libxml2 (or build them from source).  \u003ca href=\"http://xmlsoft.org/\"\u003exmlsoft\u003c/a\u003e has a link to the MS Windows binary distribution.\u003c/p\u003e\n\u003cp\u003eIf you have a TEA build environment setup, just use the normal \u003cspan class=\"literal\"\u003econfigure/make/make install\u003c/span\u003e pattern.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv class=\"section\"\u003e\n\u003ch5\u003e\n\u003ca name=\"id18987\"\u003e\u003c/a\u003eWindows (NMAKE/VC++ 6.0)\u003c/h5\u003e\n\u003cdiv class=\"note\"\u003eTclXML/libxml2 is built with MSYS/MINGW, see above, so this build system is untested.\u003c/div\u003e\n\u003cp\u003eAlternatively, the \u003ctt\u003ewin\u003c/tt\u003e subdirectory contains a \u003ctt\u003emakefile.vc\u003c/tt\u003e file for Visual Studio C++ v6.0.  In a Command Prompt window set up your environment so that \u003ctt\u003enmake\u003c/tt\u003e is on the path (by running \u003ctt\u003eVCVARS32.BAT\u003c/tt\u003e), then type the following:\u003c/p\u003e\n\u003cdiv class=\"informalexample\"\u003e\u003cpre\u003e\u003cdiv class=\"programlisting\"\u003e\u003cpre\u003enmake -f makefile.vc TCLDIR=\u003cem\u003eC:\\Path\\To\\Tcl\u003c/em\u003e INSTALLDIR=\u003cem\u003eC:\\Path\\To\\Tcl\u003c/em\u003e LIBZDIR=\u003cem\u003eC:\\Path\\To\\libz\u003c/em\u003e LIBICONVDIR=\u003cem\u003eC:\\Path\\To\\libiconv\u003c/em\u003e LIBXML2DIR=\u003cem\u003eC:\\Path\\To\\libxml2\u003c/em\u003e LIBXSLTDIR=\u003cem\u003eC:\\Path\\To\\libxslt\u003c/em\u003e\u003c/pre\u003e\u003c/div\u003e\u003c/pre\u003e\u003c/div\u003e\n\u003cp\u003eAs an example, on my system I have Tcl installed in \u003ctt\u003eC:\\Tcl\u003c/tt\u003e and the libxml2 and libxslt binaries unpacked in the directory \u003ctt\u003eC:\\gnome\u003c/tt\u003e.  Accordingly, I would use the following command line:\u003c/p\u003e\n\u003cdiv class=\"informalexample\"\u003e\u003cpre\u003e\u003cdiv class=\"programlisting\"\u003e\u003cpre\u003enmake -f makefile.vc TCLDIR=C:\\Tcl INSTALLDIR=C:\\Tcl LIBZDIR=C:\\gnome\\zlib-1.1.4.win32 LIBICONVDIR=C:\\gnome\\libiconv-1.9.1.win32 LIBXML2DIR=C:\\gnome\\libxml2-2.7.2.win32 LIBXSLTDIR=C:\\gnome\\libxslt-1.1.24.win32\u003c/pre\u003e\u003c/div\u003e\u003c/pre\u003e\u003c/div\u003e\n\u003cp\u003eInstall the package by appending 'install' to the command line used above, for example:\u003c/p\u003e\n\u003cdiv class=\"informalexample\"\u003e\u003cpre\u003e\u003cdiv class=\"programlisting\"\u003e\u003cpre\u003enmake -f makefile.vc TCLDIR=\u003cem\u003eC:\\Path\\To\\Tcl\u003c/em\u003e INSTALLDIR=\u003cem\u003eC:\\Path\\To\\Tcl\u003c/em\u003e LIBZDIR=\u003cem\u003eC:\\Path\\To\\libz\u003c/em\u003e LIBICONVDIR=\u003cem\u003eC:\\Path\\To\\libiconv\u003c/em\u003e LIBXML2DIR=\u003cem\u003eC:\\Path\\To\\libxml2\u003c/em\u003e LIBXSLTDIR=\u003cem\u003eC:\\Path\\To\\libxslt\u003c/em\u003e install\u003c/pre\u003e\u003c/div\u003e\u003c/pre\u003e\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"section\"\u003e\n\u003ch5\u003e\n\u003ca name=\"id19109\"\u003e\u003c/a\u003eMacintosh OS X\u003c/h5\u003e\n\u003cdiv class=\"note\"\u003eBinary distributions of libxml2, libxslt and TclXML as frameworks are provided by \u003ca href=\"http://www.explain.com.au/oss/\"\u003eExplain\u003c/a\u003e.\u003c/div\u003e\n\u003cp\u003eThere are two ways to build TclXML under Mac OS X:\u003c/p\u003e\n\u003col\u003e\n\u003cli\u003e\u003cp\u003eThe usual Unix way, see above.\u003c/p\u003e\u003c/li\u003e\n\u003cli\u003e\u003cp\u003eAs an embedded Framework using Xcode.\u003c/p\u003e\u003c/li\u003e\n\u003c/ol\u003e\n\u003cp\u003eThe \u003ctt\u003emacosx\u003c/tt\u003e directory contains the Xcode files for building under OS X (Leopard/Panther).  TclXML/libxml2 has been tested on OS X 10.5 (or is that X.5?).\u003c/p\u003e\n\u003cp\u003eStart-up the project.  Make sure that the references to the libxml2 and Tcl external frameworks are correct.  Select the 'Make' target and build.  This builds everything.  The result is two Mac OS X Frameworks; a \"normal\" and an \"embedded\".  The embedded framework will be in the \u003ctt\u003eembedded\u003c/tt\u003e subdirectory of the Build Products directory.  Copy \u003ctt\u003etclxml.framework\u003c/tt\u003e to any of the usual places for frameworks (\u003ctt\u003e~/Library/Frameworks\u003c/tt\u003e, \u003ctt\u003e/Library/Frameworks\u003c/tt\u003e, etc).\u003c/p\u003e\n\u003cp\u003eFor earlier version of OS X using Project Builder, you will have to retrieve a previous version of the Project Builder files from the CVS repository.\u003c/p\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"section\"\u003e\n\u003ch3\u003e\n\u003ca name=\"id19193\"\u003e\u003c/a\u003eUsage\u003c/h3\u003e\n\u003cp\u003eSee \u003ca href=\"http://tclxml.sourceforge.net/\"\u003ethe website\u003c/a\u003e for links to tutorials and the reference manual.\u003c/p\u003e\n\u003cp\u003eIn the meantime, here's a quick tutorial:\u003c/p\u003e\n\u003cdiv class=\"section\"\u003e\n\u003ch4\u003e\n\u003ca name=\"id19216\"\u003e\u003c/a\u003eParsing XML, Streaming\u003c/h4\u003e\n\u003cp\u003eThis is the lowest-level access to an XML document; use SAX-like events to stream through the document. The simple program below counts the number of characters in the content of an XML document.\u003c/p\u003e\n\u003cdiv class=\"programlisting\"\u003e\u003cpre\u003e\npackage require xml 3.2\n\nset parser [xml::parser]\n$parser configure -elementstartcommand EStart \\\n    -characterdatacommand PCData\n\nproc EStart {tag attlist args} {\n    array set attr $attlist\n    puts \"Element \\\"$tag\\\" started with [array size attr] attributes\"\n}\n\nproc PCData text {\n    incr ::count [string length $text]\n}\n\nset count 0\n$parser parse [read stdin]\n\nputs \"The document contains $count characters\"\nexit 0\n\u003c/pre\u003e\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"section\"\u003e\n\u003ch4\u003e\n\u003ca name=\"id19244\"\u003e\u003c/a\u003eParsing XML with DOM\u003c/h4\u003e\n\u003cp\u003eThis is the next level up in accessing an XML document; use the Document Object Model (DOM) to view the XML document as a tree. The simple program below counts the number of characters in the content of an XML document.\u003c/p\u003e\n\u003cdiv class=\"programlisting\"\u003e\u003cpre\u003e\npackage require xml 3.2\n\nset doc [dom::parse [read stdin]]\nset count 0\nforeach textNode [dom::selectNode $doc //text()] {\n    incr count [string length [$textNode cget -nodeValue]]\n}\n\nputs \"The document contains $count characters\"\n      \u003c/pre\u003e\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"section\"\u003e\n\u003ch4\u003e\n\u003ca name=\"id19268\"\u003e\u003c/a\u003eTransforming XML with XSLT\u003c/h4\u003e\n\u003cp\u003eThis is the highest level in processing an XML document; use a XSL stylesheet to transform a XML document. The simple program below reads two XML documents, compiles one into a XSL stylesheet and performs the transformation.\u003c/p\u003e\n\u003cdiv class=\"programlisting\"\u003e\u003cpre\u003e\npackage require xml 3.2\n\nset chan [open \"count.xsl\"]\nset styleDoc [dom::parse [read $chan]]\nclose $chan\nset sourceDoc [dom::parse [read stdin]]\n\nset style [xslt::compile $styleDoc]\nset resultDoc [$style transform $sourceDoc]\n\nputs [dom::serialize $resultDoc]\n      \u003c/pre\u003e\u003c/div\u003e\n\u003cp\u003eThe XSL stylesheet \u003ctt\u003ecount.xsl\u003c/tt\u003e, which counts the number of characters in the source document, looks like this:\u003c/p\u003e\n\u003cdiv class=\"programlisting\"\u003e\u003cpre\u003e\n\u0026lt;xsl:stylesheet version='1.0'\n  xmlns:xsl='http://www.w3.org/1999/XSL/Transform'\u0026gt;\n\n  \u0026lt;xsl:template match='/'\u0026gt;\n    \u0026lt;xsl:text\u0026gt;The document contains \u0026lt;/xsl:text\u0026gt;\n    \u0026lt;xsl:call-template name='add'\u0026gt;\n      \u0026lt;xsl:with-param name='nodes' select='//text()'/\u0026gt;\n    \u0026lt;/xsl:call-template\u0026gt;\n    \u0026lt;xsl:text\u0026gt; characters.\n\u0026lt;/xsl:text\u0026gt;\n  \u0026lt;/xsl:template\u0026gt;\n\n  \u0026lt;xsl:template name='add'\u0026gt;\n    \u0026lt;xsl:param name='sum' select='0'/\u0026gt;\n    \u0026lt;xsl:param name='nodes' select='/..'/\u0026gt;\n\n    \u0026lt;xsl:choose\u0026gt;\n      \u0026lt;xsl:when test='not($nodes)'\u0026gt;\n        \u0026lt;xsl:value-of select='$sum'/\u0026gt;\n      \u0026lt;/xsl:when\u0026gt;\n      \u0026lt;xsl:otherwise\u0026gt;\n        \u0026lt;xsl:call-template name='add'\u0026gt;\n          \u0026lt;xsl:with-param name='sum'\n            select='$sum + string-length($nodes[1])'/\u0026gt;\n          \u0026lt;xsl:with-param name='nodes'\n            select='$nodes[position() != 1]'/\u0026gt;\n        \u0026lt;/xsl:call-template\u0026gt;\n      \u0026lt;/xsl:otherwise\u0026gt;\n    \u0026lt;/xsl:choose\u0026gt;\n  \u0026lt;/xsl:template\u0026gt;\n\u0026lt;/xsl:stylesheet\u0026gt;\n\u003c/pre\u003e\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"section\"\u003e\n\u003ch3\u003e\n\u003ca name=\"id19306\"\u003e\u003c/a\u003eXPath\u003c/h3\u003e\n\u003cp\u003eIn addition to XML parsing packages, TclXML also provides a package for parsing XPath location paths.  The XPath package only parsing the path's syntax, it does interpret the path.  See \u003ca href=\"http://tclxml.sourceforge.net/tcldom.html\"\u003eTclDOM\u003c/a\u003e for a package that will interpret XPath location paths.\u003c/p\u003e\n\u003cdiv class=\"note\"\u003eThis package is in its infancy, and does not support the full range of XPath features.  Only a very limited subset of location paths are supported, of the form \"/simple/example[2]\".  Paths within predicates will definitely fail.\u003c/div\u003e\n\u003cp\u003eTo use the XPath package:\u003c/p\u003e\n\u003cdiv class=\"programlisting\"\u003e\u003cpre\u003e\npackage require xpath\n\u003c/pre\u003e\u003c/div\u003e\n\u003cp\u003eTo parse a location path:\u003c/p\u003e\n\u003cdiv class=\"programlisting\"\u003e\u003cpre\u003e\nxpath::split {/simple/example}\n\u003c/pre\u003e\u003c/div\u003e\n\u003cp\u003eThis returns a Tcl list, each element of which is a three element sublist: {axis node-test {?predicate ...?}}.\u003c/p\u003e\n\u003c/div\u003e\n\u003c/div\u003e\u003c/body\u003e\n\u003c/html\u003e\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Folebole%2Ftclxml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Folebole%2Ftclxml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Folebole%2Ftclxml/lists"}