1# cgi2dom.tcl -- 2# 3# Turns CGI parameters into a DOM document 4# 5# Copyright (c) 2000-2002 Zveno Pty Ltd 6# 7# $Id: cgi2dom.tcl,v 1.3 2002/12/10 05:17:41 balls Exp $ 8 9package require dom 2.5 10package require xpath 11 12package provide cgi2dom 1.1 13 14namespace eval cgi2dom { 15 namespace export createdocument 16} 17 18# cgi2dom::createdocument -- 19# 20# Construct a DOM document from XPath locations paths. 21# 22# Arguments: 23# specs List of XPath location path specifications 24# given as location-path/cdata pairs 25# 26# Results: 27# Returns token for new DOM document 28 29proc cgi2dom::createdocument specs { 30 set doc [dom::DOMImplementation create] 31 32 foreach {path value} $specs { 33 if {![string match /* $path]} continue 34 35 set node [dom::DOMImplementation createNode $doc $path] 36 if {[string length $value]} { 37 switch [dom::node cget $node -nodeType] { 38 element { 39 dom::document createTextNode $node $value 40 } 41 textNode { 42 dom::node configure $node -nodeValue $value 43 } 44 default {} 45 } 46 } 47 } 48 49 return $doc 50} 51 52 53 54