TclXML is [Explain]'s [XML] extension, based at http://sf.net/projects/tclxml/ . What: TclXML Where: http://tclxml.sf.net/ http://tclxml.sf.net/combo.html http://sf.net/project/showfiles.php?group_id=13178 http://tclsoap.sf.net/tclxmldom25.zip http://webperso.easyconnect.fr/bdesgraupes/tcl.html Description: This project covers a range of specifications and tools for processing and manipulating XML documents using Tcl. Collectively these tools are known as TclXML. Includes a parser written in Tcl which has equivalent functionality to TclExpat, known as the "native" TclXML parser (now also available for download). Check the code for some introductory work on an XML DTD parser. A mailing list is available. Binary versions for MacOS X and Windows are available = see the combo html page above. The current version is 3.1 . Updated: 11/2005 Contact: mailto:Steve.Ball@explain.com.au As of September 2001, TclXML has a pure-Tcl [XPath] parser. Packages build on top of this functionality are [TclDOM] and [TclXSLT]. All of these packages are part of the [ActiveTcl] Batteries Included distribution. ---- There have been some people having problems loading the TclDOM and TclXML packages into Safe interpreters. The problem is that the safe package restricts filenames to 14 characters. TclXML has tclparser-8.1.tcl as one of its files, which exceeds this limit. Here is the TclSOAP solution which removes this restriction: proc SOAP::CGI::createInterp {interp path} { set slave [safe::interpCreate $interp] safe::interpAddToAccessPath $slave $path # override the safe restrictions so we can load our # packages (actually the xml package files) proc ::safe::CheckFileName {slave file} { if {![file exists $file]} {error "file non-existent"} if {![file readable $file]} {error "file not readable"} } return $slave } This returns a safe interpreter for which interp eval ''"package require xml"'' should work. [PT] ---- [[As people keep turning up asking for tutorials on getting started with TclXML--the most basic things, like retrieval of one value from one tag of a single document--I want to make a point at least of putting a few links here which point to Steve's explanations in the mailing list.]] [Dave Griffin] offers a sample retrieval of values from a DOM tree: (19-Aug-2004 Note: This example seems to have stopped working! Did the getElementsByTagName method become "unimplemented" at some point? -dmg) ([SRB] 20-Aug-2004 Answer: The API changed some time ago. getElementsByTagName is a "live-list"; i.e., its return value is the name of a variable that contains the list of matching nodes. This variable must be dereferenced to get the actual node tokens. In addition, the result is a set (list) of nodes so you must handle that, but in this simple case just getting the first node is sufficient. E.g. set sr [dom::document getElementsByTagName $d SampleRequest] should be set sr [lindex [set [dom::document getElementsByTagName $d SampleRequest]] 0] Sounds complicated? That's because it is. A simpler and better way is to use [XPath]: set sr [dom::document selectNode $d /SampleRequest] set purl [$sr selectNode PostingURL] SRB) package require xml package require dom set xmlSrc { FooBar } # First you parse the XML, the result is held in token d. set xmlSrc [string trim $xmlSrc] ;# v2.6 barfed w/o this set d [dom::DOMImplementation parse $xmlSrc] # One way in is to parse it by the assumed structure and # use the Document interface -style of query. This code isn't # flexible at all and only highlights how the dom methods # can be used. # First find the SampleRequest element in the DOCUMENT set sr [set [dom::document getElementsByTagName $d SampleRequest]] # Next retrieve the two sub-elements in SampleRequest set purl [set [dom::element getElementsByTagName $sr PostingURL]] set pword [set [dom::element getElementsByTagName $sr Password]] # Now we will retrieve the url attribute of PostingURL set url [dom::element getAttribute $purl url] # url == "http://foo.com/some/service/url" puts "url = $url" # Finally, we want to retrieve the password. This is non-obvious. # The value "FooBar" is actually in a "textNode" child of pword, # so you have to do ferret it out with generic node commands. set pwordv [dom::node children $pword] # You could have also used: dom::node cget $pword -firstchild # dom::node cget $pwordv -nodeType -> textNode set password [dom::node cget $pwordv -nodeValue] # password == "FooBar" puts "password = $password" Note: The above example did not work (at least not with my TclXML 3.0). It was missing the second "set" command in order to access the data returned by the dom::document and dom::element instructions. meh (16/03/2007): The above example did not work for me either. The 'dom::DOMImplementation parse' command always returns an error, consisting of a blank line for me, and TCL is unable to set the variable 'd'. Of course, this then makes the rest of the procedure fail. Using version 3.0, will try another version (Debian repos gave me 3.0 :/ ). Any other ideas? ---- Steve's starting to make courseware available through http://www.zveno.com/courses/samples/XML-App-Dev-Tcl/ (this link is broken :-( ) ''[escargo] 05/05/05'' - As of this date, there is nothing there, perhaps because Steve isn't at zveno any more. [SRB] 2005-11-07 - that's right, I'm now at [Explain]. We'll try and get some of these tutorials available ASAP. ---- The 2001 article, "Programming XML and Web services in TCL" [http://www-106.ibm.com/developerworks/webservices/library/ws-xtcl.html], features TclXML. ---- The TclXML SourceForge Site mentions this document: TclXML: The Next Generation. Presented at the 9th Tcl Workshop, 16-19 September 2002, Vancouver Canada. [RA] 2006-11-24: A link is available here: http://aspn.activestate.com/ASPN/Tcl/TclConferencePapers2002/Tcl2002papers/ball-tclxml/Ball-paper.pdf [SRB] 2005-11-07 - See above. My move from Zveno has resulted in a few pages being dropped. I'm working on getting these restored. ---- [Steve Ball] [[ [Category Package] | [Category XML] | ]]