File: cgi2dom.tcl

package info (click to toggle)
tclxml 3.3~svn11-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 4,392 kB
  • sloc: ansic: 13,292; tcl: 11,656; xml: 3,269; sh: 559; makefile: 15
file content (56 lines) | stat: -rw-r--r-- 1,167 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# cgi2dom.tcl --
#
#	Turns CGI parameters into a DOM document
#
# Copyright (c) 2000-2002 Zveno Pty Ltd
#
# See the file "LICENSE" in this distribution for information on usage and
# redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
# $Id: cgi2dom.tcl,v 1.4 2003/12/09 04:56:40 balls Exp $

package require dom 2.5
package require xpath

package provide cgi2dom 1.1

namespace eval cgi2dom {
    namespace export createdocument
}

# cgi2dom::createdocument --
#
#	Construct a DOM document from XPath locations paths.
#
# Arguments:
#	specs	List of XPath location path specifications
#		given as location-path/cdata pairs
#
# Results:
#	Returns token for new DOM document

proc cgi2dom::createdocument specs {
    set doc [dom::DOMImplementation create]

    foreach {path value} $specs {
	if {![string match /* $path]} continue

	set node [dom::DOMImplementation createNode $doc $path]
	if {[string length $value]} {
	    switch [dom::node cget $node -nodeType] {
		element {
		    dom::document createTextNode $node $value
		}
		textNode {
		    dom::node configure $node -nodeValue $value
		}
		default {}
	    }
	}
    }

    return $doc
}