Index: openacs-4/packages/acs-tcl/tcl/xml-1-dom-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/xml-1-dom-procs.tcl,v diff -u -r1.11.2.4 -r1.11.2.5 --- openacs-4/packages/acs-tcl/tcl/xml-1-dom-procs.tcl 10 Jul 2023 08:43:13 -0000 1.11.2.4 +++ openacs-4/packages/acs-tcl/tcl/xml-1-dom-procs.tcl 27 Aug 2024 10:06:37 -0000 1.11.2.5 @@ -4,7 +4,7 @@ # # This file implements the Tcl language binding for the DOM - # the Document Object Model. Support for the core specification -# is given here. Layered support for specific languages, +# is given here. Layered support for specific languages, # such as HTML and XML, will be in separate modules. # # Copyright (c) 1998 Zveno Pty Ltd @@ -71,7 +71,7 @@ proc dom::GetHandle {type token varName} { if {![info exists $token]} { - return -code error "invalid token \"$token\"" + return -code error "invalid token \"$token\"" } upvar 1 $varName data @@ -134,220 +134,220 @@ switch -- $method { - hasFeature { + hasFeature { - if {[llength $args] != 2} { - return -code error "wrong number of arguments" - } + if {[llength $args] != 2} { + return -code error "wrong number of arguments" + } - # Later on, could use Tcl package facility - if {[regexp {create|destroy|parse|serialize|trim} [lindex $args 0]]} { - if {[lindex $args 1] eq "1.0" } { - return 1 - } else { - return 0 - } - } else { - return 0 - } + # Later on, could use Tcl package facility + if {[regexp {create|destroy|parse|serialize|trim} [lindex $args 0]]} { + if {[lindex $args 1] eq "1.0" } { + return 1 + } else { + return 0 + } + } else { + return 0 + } - } + } - create { + create { - # Bootstrap a document instance + # Bootstrap a document instance - switch [llength $args] { - 0 { - # Allocate unique document array name - set name [namespace current]::document[incr DOMImplementationCounter] - } - 1 { - # Use array name provided. Should check that it is safe. - set name [lindex $args 0] - unset -nocomplain $name - } - default { - return -code error "wrong number of arguments" - } - } + switch [llength $args] { + 0 { + # Allocate unique document array name + set name [namespace current]::document[incr DOMImplementationCounter] + } + 1 { + # Use array name provided. Should check that it is safe. + set name [lindex $args 0] + unset -nocomplain $name + } + default { + return -code error "wrong number of arguments" + } + } - set varPrefix ${name}var - set arrayPrefix ${name}arr + set varPrefix ${name}var + set arrayPrefix ${name}arr - array set $name [list counter 1 \ - node1 [list id node1 docArray $name \ - node:nodeType documentFragment \ - node:parentNode {} \ - node:childNodes ${varPrefix}1 \ - documentFragment:masterDoc node1 \ - document:implementation {} \ - document:xmldecl {version 1.0} \ - document:documentElement {} \ - document:doctype {} \ - ]] + array set $name [list counter 1 \ + node1 [list id node1 docArray $name \ + node:nodeType documentFragment \ + node:parentNode {} \ + node:childNodes ${varPrefix}1 \ + documentFragment:masterDoc node1 \ + document:implementation {} \ + document:xmldecl {version 1.0} \ + document:documentElement {} \ + document:doctype {} \ + ]] - # Initialise child node list - set ${varPrefix}1 {} + # Initialise child node list + set ${varPrefix}1 {} - # Return the new top-level node - return ${name}(node1) + # Return the new top-level node + return ${name}(node1) - } + } - destroy { + destroy { - # Cleanup a document + # Cleanup a document - if {[llength $args] != 1} { - return -code error "wrong number of arguments" - } - array set node [set [lindex $args 0]] + if {[llength $args] != 1} { + return -code error "wrong number of arguments" + } + array set node [set [lindex $args 0]] - # Patch from Gerald Lester + # Patch from Gerald Lester - ## - ## First release all the associated variables - ## - upvar #0 $node(docArray) docArray - for {set i 0} {$i < $docArray(counter)} {incr i} { - unset -nocomplain ${docArrayName}var$i - unset -nocomplain ${docArrayName}arr$i - } - - ## - ## Then release the main document array - ## - if {![info exists $node(docArray)]} { - return -code error "unable to destroy document" - } + ## + ## First release all the associated variables + ## + upvar #0 $node(docArray) docArray + for {set i 0} {$i < $docArray(counter)} {incr i} { + unset -nocomplain ${docArrayName}var$i + unset -nocomplain ${docArrayName}arr$i + } + + ## + ## Then release the main document array + ## + if {![info exists $node(docArray)]} { + return -code error "unable to destroy document" + } unset -nocomplain $node(docArray) - return {} + return {} - } + } - parse { + parse { - # This implementation allows use of either of two event-based, - # non-validating XML parsers: - # . TclXML Tcl-only parser (version 1.3 or higher) - # . TclExpat parser + # This implementation allows use of either of two event-based, + # non-validating XML parsers: + # . TclXML Tcl-only parser (version 1.3 or higher) + # . TclExpat parser - array set opts {-parser {} -progresscommand {} -chunksize 8196} - if {[catch {array set opts [lrange $args 1 end]}]} { - return -code error "bad configuration options" - } + array set opts {-parser {} -progresscommand {} -chunksize 8196} + if {[catch {array set opts [lrange $args 1 end]}]} { + return -code error "bad configuration options" + } - # Create a state array for this parse session - set state [namespace current]::parse[incr DOMImplementationCounter] - array set $state [array get opts -*] - array set $state [list progCounter 0] - set errorCleanup {} + # Create a state array for this parse session + set state [namespace current]::parse[incr DOMImplementationCounter] + array set $state [array get opts -*] + array set $state [list progCounter 0] + set errorCleanup {} - switch -- $opts(-parser) { - expat { - if {[catch {package require expat} version]} { - eval $errorCleanup - return -code error "expat extension is not available" - } - set parser [expat [namespace current]::xmlparser] - } - tcl { - if {[catch {package require xml 1.3} version]} { - eval $errorCleanup - return -code error "XML parser package is not available" - } - set parser [::xml::parser xmlparser] - } - default { - # Automatically determine which parser to use - if {[catch {package require expat} version]} { - if {[catch {package require xml 1.3} version]} { - eval $errorCleanup - return -code error "unable to load XML parser" - } else { - set parser [::xml::parser xmlparser] - } - } else { - set parser [expat [namespace current]::xmlparser] - } - } - } + switch -- $opts(-parser) { + expat { + if {[catch {package require expat} version]} { + eval $errorCleanup + return -code error "expat extension is not available" + } + set parser [expat [namespace current]::xmlparser] + } + tcl { + if {[catch {package require xml 1.3} version]} { + eval $errorCleanup + return -code error "XML parser package is not available" + } + set parser [::xml::parser xmlparser] + } + default { + # Automatically determine which parser to use + if {[catch {package require expat} version]} { + if {[catch {package require xml 1.3} version]} { + eval $errorCleanup + return -code error "unable to load XML parser" + } else { + set parser [::xml::parser xmlparser] + } + } else { + set parser [expat [namespace current]::xmlparser] + } + } + } - $parser configure \ - -elementstartcommand [namespace code [list ParseElementStart $state]] \ - -elementendcommand [namespace code [list ParseElementEnd $state]] \ - -characterdatacommand [namespace code [list ParseCharacterData $state]] \ - -processinginstructioncommand [namespace code [list ParseProcessingInstruction $state]] \ - -final true + $parser configure \ + -elementstartcommand [namespace code [list ParseElementStart $state]] \ + -elementendcommand [namespace code [list ParseElementEnd $state]] \ + -characterdatacommand [namespace code [list ParseCharacterData $state]] \ + -processinginstructioncommand [namespace code [list ParseProcessingInstruction $state]] \ + -final true - # TclXML has features missing from expat - catch { - $parser configure \ - -xmldeclcommand [namespace code [list ParseXMLDeclaration $state]] \ - -doctypecommand [namespace code [list ParseDocType $state]] - } + # TclXML has features missing from expat + catch { + $parser configure \ + -xmldeclcommand [namespace code [list ParseXMLDeclaration $state]] \ + -doctypecommand [namespace code [list ParseDocType $state]] + } - # Create top-level document - array set $state [list docNode [DOMImplementation create]] - array set $state [list current [lindex [array get $state docNode] 1]] + # Create top-level document + array set $state [list docNode [DOMImplementation create]] + array set $state [list current [lindex [array get $state docNode] 1]] - # Parse data - # Bug in TclExpat - doesn't handle non-final inputs - if {0 && [string length $opts(-progresscommand)]} { - $parser configure -final false - while {[string length [lindex $args 0]]} { - $parser parse [string range [lindex $args 0] 0 $opts(-chunksize)] - #set args [lreplace $args 0 0 \ + # Parse data + # Bug in TclExpat - doesn't handle non-final inputs + if {0 && [string length $opts(-progresscommand)]} { + $parser configure -final false + while {[string length [lindex $args 0]]} { + $parser parse [string range [lindex $args 0] 0 $opts(-chunksize)] + #set args [lreplace $args 0 0 \ # [string range [lindex $args 0] $opts(-chunksize) end]] lset args 0 [string range [lindex $args 0] $opts(-chunksize) end] - uplevel #0 $opts(-progresscommand) - } - $parser configure -final true - } elseif {[catch {$parser parse [lindex $args 0]} err]} { - catch {rename $parser {}} - unset -nocomplain $state - return -code error $err - } + uplevel #0 $opts(-progresscommand) + } + $parser configure -final true + } elseif {[catch {$parser parse [lindex $args 0]} err]} { + catch {rename $parser {}} + unset -nocomplain $state + return -code error $err + } - # Free data structures which are no longer required - catch {rename $parser {}} + # Free data structures which are no longer required + catch {rename $parser {}} - set doc [lindex [array get $state docNode] 1] - unset $state - return $doc + set doc [lindex [array get $state docNode] 1] + unset $state + return $doc - } + } - serialize { + serialize { - if {[llength $args] < 1} { - return -code error "wrong number of arguments" - } + if {[llength $args] < 1} { + return -code error "wrong number of arguments" + } - GetHandle documentFragment [lindex $args 0] node - return [eval [list Serialize:$node(node:nodeType)] $args] + GetHandle documentFragment [lindex $args 0] node + return [eval [list Serialize:$node(node:nodeType)] $args] - } + } - trim { + trim { - # Removes textNodes that only contain white space + # Removes textNodes that only contain white space - if {[llength $args] != 1} { - return -code error "wrong number of arguments" - } + if {[llength $args] != 1} { + return -code error "wrong number of arguments" + } - Trim [lindex $args 0] + Trim [lindex $args 0] - return {} + return {} - } + } - default { - return -code error "unknown method \"$method\"" - } + default { + return -code error "unknown method \"$method\"" + } } @@ -381,127 +381,127 @@ set result {} switch -- $method { - cget { - if {[llength $args] != 1} { - return -code error "too many arguments" - } - if {[regexp [format {^-(%s)$} $documentOptionsRO] [lindex $args 0] discard option]} { - return $node(document:$option) - } elseif {[regexp [format {^-(%s)$} $documentOptionsRW] [lindex $args 0] discard option]} { - return $node(document:$option) - } else { - return -code error "unknown option \"[lindex $args 0]\"" - } - } - configure { - if {[llength $args] == 1} { - return [document cget $token [lindex $args 0]] - } elseif {[llength $args] % 2} { - return -code error "no value specified for option \"[lindex $args end]\"" - } else { - foreach {option value} $args { - if {[regexp [format {^-(%s)$} $documentOptionsRW] $option discard opt]} { - set node(document:$opt) $value - } elseif {[regexp [format {^-(%s)$} $documentOptionsRO] $option discard opt]} { - return -code error "attribute \"$option\" is read-only" - } else { - return -code error "unknown option \"$option\"" - } - } - } + cget { + if {[llength $args] != 1} { + return -code error "too many arguments" + } + if {[regexp [format {^-(%s)$} $documentOptionsRO] [lindex $args 0] discard option]} { + return $node(document:$option) + } elseif {[regexp [format {^-(%s)$} $documentOptionsRW] [lindex $args 0] discard option]} { + return $node(document:$option) + } else { + return -code error "unknown option \"[lindex $args 0]\"" + } + } + configure { + if {[llength $args] == 1} { + return [document cget $token [lindex $args 0]] + } elseif {[llength $args] % 2} { + return -code error "no value specified for option \"[lindex $args end]\"" + } else { + foreach {option value} $args { + if {[regexp [format {^-(%s)$} $documentOptionsRW] $option discard opt]} { + set node(document:$opt) $value + } elseif {[regexp [format {^-(%s)$} $documentOptionsRO] $option discard opt]} { + return -code error "attribute \"$option\" is read-only" + } else { + return -code error "unknown option \"$option\"" + } + } + } - PutHandle $token node + PutHandle $token node - } + } - createElement { - if {[llength $args] != 1} { - return -code error "wrong number of arguments" - } + createElement { + if {[llength $args] != 1} { + return -code error "wrong number of arguments" + } - # Check that the element name is kosher - # BUG: The definition of 'Letter' here as ASCII letters - # is not sufficient. Also, CombiningChar and Extenders - # must be added. - if {![regexp {^[A-Za-z_:][-A-Za-z0-9._:]*$} [lindex $args 0]]} { - return -code error "invalid element name \"[lindex $args 0]\"" - } + # Check that the element name is kosher + # BUG: The definition of 'Letter' here as ASCII letters + # is not sufficient. Also, CombiningChar and Extenders + # must be added. + if {![regexp {^[A-Za-z_:][-A-Za-z0-9._:]*$} [lindex $args 0]]} { + return -code error "invalid element name \"[lindex $args 0]\"" + } - # Invoke internal factory function - set result [CreateElement $token [lindex $args 0] {}] + # Invoke internal factory function + set result [CreateElement $token [lindex $args 0] {}] - } - createDocumentFragment { - if {[llength $args]} { - return -code error "wrong number of arguments" - } + } + createDocumentFragment { + if {[llength $args]} { + return -code error "wrong number of arguments" + } - set result [CreateGeneric $token node:nodeType documentFragment] - } - createTextNode { - if {[llength $args] != 1} { - return -code error "wrong number of arguments" - } + set result [CreateGeneric $token node:nodeType documentFragment] + } + createTextNode { + if {[llength $args] != 1} { + return -code error "wrong number of arguments" + } - set result [CreateTextNode $token [lindex $args 0]] - } - createComment { - if {[llength $args] != 1} { - return -code error "wrong number of arguments" - } + set result [CreateTextNode $token [lindex $args 0]] + } + createComment { + if {[llength $args] != 1} { + return -code error "wrong number of arguments" + } - set result [CreateGeneric $token node:nodeType comment node:nodeValue [lindex $args 0]] - } - createCDATASection { - if {[llength $args] != 1} { - return -code error "wrong number of arguments" - } + set result [CreateGeneric $token node:nodeType comment node:nodeValue [lindex $args 0]] + } + createCDATASection { + if {[llength $args] != 1} { + return -code error "wrong number of arguments" + } - set result [CreateGeneric $token node:nodeType CDATASection node:nodeValue [lindex $args 0]] - } - createProcessingInstruction { - if {[llength $args] != 2} { - return -code error "wrong number of arguments" - } + set result [CreateGeneric $token node:nodeType CDATASection node:nodeValue [lindex $args 0]] + } + createProcessingInstruction { + if {[llength $args] != 2} { + return -code error "wrong number of arguments" + } - set result [CreateGeneric $token node:nodeType processingInstruction \ - node:nodeName [lindex $args 0] node:nodeValue [lindex $args 1]] - } - createAttribute { - if {[llength $args] != 1} { - return -code error "wrong number of arguments" - } + set result [CreateGeneric $token node:nodeType processingInstruction \ + node:nodeName [lindex $args 0] node:nodeValue [lindex $args 1]] + } + createAttribute { + if {[llength $args] != 1} { + return -code error "wrong number of arguments" + } - set result [CreateGeneric $token node:nodeType attribute node:nodeName [lindex $args 0]] - } - createEntity { - set result [CreateGeneric $token node:nodeType entity] - } - createEntityReference { - set result [CreateGeneric $token node:nodeType entityReference] - } + set result [CreateGeneric $token node:nodeType attribute node:nodeName [lindex $args 0]] + } + createEntity { + set result [CreateGeneric $token node:nodeType entity] + } + createEntityReference { + set result [CreateGeneric $token node:nodeType entityReference] + } - createDocTypeDecl { - # This is not a standard DOM 1.0 method - if {[llength $args] < 1 || [llength $args] > 5} { - return -code error "wrong number of arguments" - } + createDocTypeDecl { + # This is not a standard DOM 1.0 method + if {[llength $args] < 1 || [llength $args] > 5} { + return -code error "wrong number of arguments" + } - lassign $args name extid dtd entities notations - set result [CreateDocType $token $name $extid $dtd $entities $notations] - } + lassign $args name extid dtd entities notations + set result [CreateDocType $token $name $extid $dtd $entities $notations] + } - getElementsByTagName { - if {[llength $args] != 1} { - return -code error "wrong number of arguments" - } + getElementsByTagName { + if {[llength $args] != 1} { + return -code error "wrong number of arguments" + } - return [Element:GetByTagName $token [lindex $args 0]] - } + return [Element:GetByTagName $token [lindex $args 0]] + } - default { - return -code error "unknown method \"$method\"" - } + default { + return -code error "unknown method \"$method\"" + } } @@ -527,13 +527,13 @@ proc dom::CreateElement {token name aList args} { if {[string length $token]} { - array set parent [set $token] - upvar #0 $parent(docArray) docArray - set docArrayName $parent(docArray) + array set parent [set $token] + upvar #0 $parent(docArray) docArray + set docArrayName $parent(docArray) } else { - array set opts $args - upvar #0 $opts(-docarray) docArray - set docArrayName $opts(-docarray) + array set opts $args + upvar #0 $opts(-docarray) docArray + set docArrayName $opts(-docarray) } set id node[incr docArray(counter)] @@ -543,12 +543,12 @@ # NB. normally we'd use Node:create here, # but inline it instead for performance set docArray($id) [list id $id docArray $docArrayName \ - node:parentNode $token \ - node:childNodes ${docArrayName}var$docArray(counter) \ - node:nodeType element \ - node:nodeName $name \ - node:nodeValue {} \ - element:attributeList ${docArrayName}arr$docArray(counter) \ + node:parentNode $token \ + node:childNodes ${docArrayName}var$docArray(counter) \ + node:nodeType element \ + node:nodeName $name \ + node:nodeValue {} \ + element:attributeList ${docArrayName}arr$docArray(counter) \ ] # Initialise associated variables @@ -562,36 +562,36 @@ if {[string length $token]} { - if {$parent(node:nodeType) eq "documentFragment" } { - if {$parent(id) == $parent(documentFragment:masterDoc)} { - if {[info exists parent(document:documentElement)] - && [string length $parent(document:documentElement)] - } { - unset docArray($id) - return -code error "document element already exists" - } else { + if {$parent(node:nodeType) eq "documentFragment" } { + if {$parent(id) == $parent(documentFragment:masterDoc)} { + if {[info exists parent(document:documentElement)] + && [string length $parent(document:documentElement)] + } { + unset docArray($id) + return -code error "document element already exists" + } else { - # Check against document type decl - if {[string length $parent(document:doctype)]} { - array set doctypedecl [set $parent(document:doctype)] - if {$name ne $doctypedecl(doctype:name) } { - return -code error "mismatch between root element type in document type declaration \"$doctypedecl(doctype:name)\" and root element \"$name\"" - } + # Check against document type decl + if {[string length $parent(document:doctype)]} { + array set doctypedecl [set $parent(document:doctype)] + if {$name ne $doctypedecl(doctype:name) } { + return -code error "mismatch between root element type in document type declaration \"$doctypedecl(doctype:name)\" and root element \"$name\"" + } - } else { - # Synthesize document type declaration - CreateDocType $token $name {} {} - # Resynchronise parent record - array set parent [set $token] - } + } else { + # Synthesize document type declaration + CreateDocType $token $name {} {} + # Resynchronise parent record + array set parent [set $token] + } - set parent(document:documentElement) $child - set $token [array get parent] - } - } - } + set parent(document:documentElement) $child + set $token [array get parent] + } + } + } - lappend $parent(node:childNodes) $child + lappend $parent(node:childNodes) $child } @@ -616,13 +616,13 @@ proc dom::CreateTextNode {token text args} { if {[string length $token]} { - array set parent [set $token] - upvar #0 $parent(docArray) docArray - set docArrayName $parent(docArray) + array set parent [set $token] + upvar #0 $parent(docArray) docArray + set docArrayName $parent(docArray) } else { - array set opts $args - upvar #0 $opts(-docarray) docArray - set docArrayName $opts(-docarray) + array set opts $args + upvar #0 $opts(-docarray) docArray + set docArrayName $opts(-docarray) } set id node[incr docArray(counter)] @@ -635,16 +635,16 @@ # Text nodes never have children, so don't create a variable set docArray($id) [list id $id docArray $docArrayName \ - node:parentNode $token \ - node:childNodes {} \ - node:nodeType textNode \ - node:nodeValue $text \ + node:parentNode $token \ + node:childNodes {} \ + node:nodeType textNode \ + node:nodeValue $text \ ] if {[string length $token]} { - # Update parent record - lappend $parent(node:childNodes) $child - set $token [array get parent] + # Update parent record + lappend $parent(node:childNodes) $child + set $token [array get parent] } return $child @@ -663,18 +663,18 @@ proc dom::CreateGeneric {token args} { if {[string length $token]} { - array set parent [set $token] - upvar #0 $parent(docArray) docArray - set docArrayName $parent(docArray) + array set parent [set $token] + upvar #0 $parent(docArray) docArray + set docArrayName $parent(docArray) } else { - array set opts $args - upvar #0 $opts(-docarray) docArray - set docArrayName $opts(-docarray) - array set tmp [array get opts] - foreach opt [array names tmp -*] { - unset tmp($opt) - } - set args [array get tmp] + array set opts $args + upvar #0 $opts(-docarray) docArray + set docArrayName $opts(-docarray) + array set tmp [array get opts] + foreach opt [array names tmp -*] { + unset tmp($opt) + } + set args [array get tmp] } set id node[incr docArray(counter)] @@ -684,16 +684,16 @@ # NB. normally we'd use Node:create here, # but inline it instead for performance set docArray($id) [eval list [list id $id docArray $docArrayName \ - node:parentNode $token \ - node:childNodes ${docArrayName}var$docArray(counter)] \ - $args + node:parentNode $token \ + node:childNodes ${docArrayName}var$docArray(counter)] \ + $args ] set ${docArrayName}var$docArray(counter) {} if {[string length $token]} { - # Update parent record - lappend $parent(node:childNodes) $child - set $token [array get parent] + # Update parent record + lappend $parent(node:childNodes) $child + set $token [array get parent] } return $child @@ -722,17 +722,17 @@ set child $doc(docArray)($id) set docArray($id) [list \ - id $id docArray $doc(docArray) \ - node:parentNode $token \ - node:childNodes {} \ - node:nodeType docType \ - node:nodeName {} \ - node:nodeValue {} \ - doctype:name $name \ - doctype:entities {} \ - doctype:notations {} \ - doctype:externalid $extid \ - doctype:internaldtd $dtd \ + id $id docArray $doc(docArray) \ + node:parentNode $token \ + node:childNodes {} \ + node:nodeType docType \ + node:nodeName {} \ + node:nodeValue {} \ + doctype:name $name \ + doctype:entities {} \ + doctype:notations {} \ + doctype:externalid $extid \ + doctype:internaldtd $dtd \ ] # NB. externalid and internaldtd are not standard DOM 1.0 attributes @@ -776,305 +776,305 @@ set result {} switch -glob -- $method { - cg* { - # cget + cg* { + # cget - # Some read-only configuration options are computed - if {[llength $args] != 1} { - return -code error "too many arguments" - } - if {[regexp [format {^-(%s)$} $nodeOptionsRO] [lindex $args 0] discard option]} { - switch -- $option { - childNodes { - # How are we going to handle documentElement? - set result $node(node:childNodes) - } - firstChild { - upvar #0 $node(node:childNodes) children - switch -- $node(node:nodeType) { - documentFragment { - set result [lindex $children 0] - catch {set result $node(document:documentElement)} - } - default { - set result [lindex $children 0] - } - } - } - lastChild { - upvar #0 $node(node:childNodes) children - switch -- $node(node:nodeType) { - documentFragment { - set result [lindex $children end] - catch {set result $node(document:documentElement)} - } - default { - set result [lindex $children end] - } - } - } - previousSibling { - # BUG: must take documentElement into account - # Find the parent node - GetHandle node $node(node:parentNode) parent - upvar #0 $parent(node:childNodes) children - set idx [lsearch $children $token] - if {$idx >= 0} { - set sib [lindex $children [incr idx -1]] - if {[llength $sib]} { - set result $sib - } else { - set result {} - } - } else { - set result {} - } - } - nextSibling { - # BUG: must take documentElement into account - # Find the parent node - GetHandle node $node(node:parentNode) parent - upvar #0 $parent(node:childNodes) children - set idx [lsearch $children $token] - if {$idx >= 0} { - set sib [lindex $children [incr idx]] - if {[llength $sib]} { - set result $sib - } else { - set result {} - } - } else { - set result {} - } - } - attributes { - if {$node(node:nodeType) ne "element" } { - set result {} - } else { - set result $node(element:attributeList) - } - } - default { - return [GetField node(node:$option)] - } - } - } elseif {[regexp [format {^-(%s)$} $nodeOptionsRW] [lindex $args 0] discard option]} { - return [GetField node(node:$option)] - } else { - return -code error "unknown option \"[lindex $args 0]\"" - } - } - co* { - # configure + # Some read-only configuration options are computed + if {[llength $args] != 1} { + return -code error "too many arguments" + } + if {[regexp [format {^-(%s)$} $nodeOptionsRO] [lindex $args 0] discard option]} { + switch -- $option { + childNodes { + # How are we going to handle documentElement? + set result $node(node:childNodes) + } + firstChild { + upvar #0 $node(node:childNodes) children + switch -- $node(node:nodeType) { + documentFragment { + set result [lindex $children 0] + catch {set result $node(document:documentElement)} + } + default { + set result [lindex $children 0] + } + } + } + lastChild { + upvar #0 $node(node:childNodes) children + switch -- $node(node:nodeType) { + documentFragment { + set result [lindex $children end] + catch {set result $node(document:documentElement)} + } + default { + set result [lindex $children end] + } + } + } + previousSibling { + # BUG: must take documentElement into account + # Find the parent node + GetHandle node $node(node:parentNode) parent + upvar #0 $parent(node:childNodes) children + set idx [lsearch $children $token] + if {$idx >= 0} { + set sib [lindex $children [incr idx -1]] + if {[llength $sib]} { + set result $sib + } else { + set result {} + } + } else { + set result {} + } + } + nextSibling { + # BUG: must take documentElement into account + # Find the parent node + GetHandle node $node(node:parentNode) parent + upvar #0 $parent(node:childNodes) children + set idx [lsearch $children $token] + if {$idx >= 0} { + set sib [lindex $children [incr idx]] + if {[llength $sib]} { + set result $sib + } else { + set result {} + } + } else { + set result {} + } + } + attributes { + if {$node(node:nodeType) ne "element" } { + set result {} + } else { + set result $node(element:attributeList) + } + } + default { + return [GetField node(node:$option)] + } + } + } elseif {[regexp [format {^-(%s)$} $nodeOptionsRW] [lindex $args 0] discard option]} { + return [GetField node(node:$option)] + } else { + return -code error "unknown option \"[lindex $args 0]\"" + } + } + co* { + # configure - if {[llength $args] == 1} { - return [document cget $token [lindex $args 0]] - } elseif {[llength $args] % 2} { - return -code error "no value specified for option \"[lindex $args end]\"" - } else { - foreach {option value} $args { - if {[regexp [format {^-(%s)$} $nodeOptionsRW] $option discard opt]} { - set node(node:$opt) $value - } elseif {[regexp [format {^-(%s)$} $nodeOptionsRO] $option discard opt]} { - return -code error "attribute \"$option\" is read-only" - } else { - return -code error "unknown option \"$option\"" - } - } - } - } + if {[llength $args] == 1} { + return [document cget $token [lindex $args 0]] + } elseif {[llength $args] % 2} { + return -code error "no value specified for option \"[lindex $args end]\"" + } else { + foreach {option value} $args { + if {[regexp [format {^-(%s)$} $nodeOptionsRW] $option discard opt]} { + set node(node:$opt) $value + } elseif {[regexp [format {^-(%s)$} $nodeOptionsRO] $option discard opt]} { + return -code error "attribute \"$option\" is read-only" + } else { + return -code error "unknown option \"$option\"" + } + } + } + } - in* { + in* { - # insertBefore + # insertBefore - # Previous and next sibling relationships are OK, - # because they are dynamically determined + # Previous and next sibling relationships are OK, + # because they are dynamically determined - if {[llength $args] < 1 || [llength $args] > 2} { - return -code error "wrong number of arguments" - } + if {[llength $args] < 1 || [llength $args] > 2} { + return -code error "wrong number of arguments" + } - GetHandle node [lindex $args 0] newChild - if {$newChild(docArray) ne $node(docArray) } { - return -code error "new node must be in the same document" - } + GetHandle node [lindex $args 0] newChild + if {$newChild(docArray) ne $node(docArray) } { + return -code error "new node must be in the same document" + } - switch [llength $args] { - 1 { - # Append as the last node - if {[string length $newChild(node:parentNode)]} { - node removeChild $newChild(node:parentNode) [lindex $args 0] - } - lappend $node(node:childNodes) [lindex $args 0] - set newChild(node:parentNode) $token - } - 2 { + switch [llength $args] { + 1 { + # Append as the last node + if {[string length $newChild(node:parentNode)]} { + node removeChild $newChild(node:parentNode) [lindex $args 0] + } + lappend $node(node:childNodes) [lindex $args 0] + set newChild(node:parentNode) $token + } + 2 { - GetHandle node [lindex $args 1] refChild - if {$refChild(docArray) ne $newChild(docArray) } { - return -code error "nodes must be in the same document" - } - set idx [lsearch [set $node(node:childNodes)] [lindex $args 1]] - if {$idx < 0} { - return -code error "no such reference child" - } else { + GetHandle node [lindex $args 1] refChild + if {$refChild(docArray) ne $newChild(docArray) } { + return -code error "nodes must be in the same document" + } + set idx [lsearch [set $node(node:childNodes)] [lindex $args 1]] + if {$idx < 0} { + return -code error "no such reference child" + } else { - # Remove from previous parent - if {[string length $newChild(node:parentNode)]} { - node removeChild $newChild(node:parentNode) [lindex $args 0] - } + # Remove from previous parent + if {[string length $newChild(node:parentNode)]} { + node removeChild $newChild(node:parentNode) [lindex $args 0] + } - # Insert into new node - set $node(node:childNodes) \ - [linsert [set $node(node:childNodes)] $idx [lindex $args 0]] - set newChild(node:parentNode) $token - } - } - } - PutHandle [lindex $args 0] newChild - } + # Insert into new node + set $node(node:childNodes) \ + [linsert [set $node(node:childNodes)] $idx [lindex $args 0]] + set newChild(node:parentNode) $token + } + } + } + PutHandle [lindex $args 0] newChild + } - rep* { + rep* { - # replaceChild + # replaceChild - if {[llength $args] != 2} { - return -code error "wrong number of arguments" - } + if {[llength $args] != 2} { + return -code error "wrong number of arguments" + } - GetHandle node [lindex $args 0] newChild - GetHandle node [lindex $args 1] oldChild + GetHandle node [lindex $args 0] newChild + GetHandle node [lindex $args 1] oldChild - # Find where to insert new child - set idx [lsearch [set $node(node:childNodes)] [lindex $args 1]] - if {$idx < 0} { - return -code error "no such old child" - } + # Find where to insert new child + set idx [lsearch [set $node(node:childNodes)] [lindex $args 1]] + if {$idx < 0} { + return -code error "no such old child" + } - # Remove new child from current parent - if {[string length $newChild(node:parentNode)]} { - node removeChild $newChild(node:parentNode) [lindex $args 0] - } + # Remove new child from current parent + if {[string length $newChild(node:parentNode)]} { + node removeChild $newChild(node:parentNode) [lindex $args 0] + } - #set $node(node:childNodes) \ - #[lreplace [set $node(node:childNodes)] $idx $idx [lindex $args 0]] + #set $node(node:childNodes) \ + #[lreplace [set $node(node:childNodes)] $idx $idx [lindex $args 0]] lset $node(node:childNodes) $idx [lindex $args 0] - set newChild(node:parentNode) $token + set newChild(node:parentNode) $token - # Update old child to reflect lack of parentage - set oldChild(node:parentNode) {} + # Update old child to reflect lack of parentage + set oldChild(node:parentNode) {} - PutHandle [lindex $args 1] oldChild - PutHandle [lindex $args 0] newChild + PutHandle [lindex $args 1] oldChild + PutHandle [lindex $args 0] newChild - set result [lindex $args 0] + set result [lindex $args 0] - } + } - rem* { + rem* { - # removeChild + # removeChild - if {[llength $args] != 1} { - return -code error "wrong number of arguments" - } - array set oldChild [set [lindex $args 0]] - if {$oldChild(docArray) != $node(docArray)} { - return -code error "node \"[lindex $args 0]\" is not a child" - } + if {[llength $args] != 1} { + return -code error "wrong number of arguments" + } + array set oldChild [set [lindex $args 0]] + if {$oldChild(docArray) != $node(docArray)} { + return -code error "node \"[lindex $args 0]\" is not a child" + } - # Remove the child from the parent - upvar #0 $node(node:childNodes) myChildren - if {[set idx [lsearch $myChildren [lindex $args 0]]] < 0} { - return -code error "node \"[lindex $args 0]\" is not a child" - } - set myChildren [lreplace $myChildren $idx $idx] + # Remove the child from the parent + upvar #0 $node(node:childNodes) myChildren + if {[set idx [lsearch $myChildren [lindex $args 0]]] < 0} { + return -code error "node \"[lindex $args 0]\" is not a child" + } + set myChildren [lreplace $myChildren $idx $idx] - # Update the child to reflect lack of parentage - set oldChild(node:parentNode) {} - set [lindex $args 0] [array get oldChild] + # Update the child to reflect lack of parentage + set oldChild(node:parentNode) {} + set [lindex $args 0] [array get oldChild] - set result [lindex $args 0] - } + set result [lindex $args 0] + } - ap* { + ap* { - # appendChild + # appendChild - if {[llength $args] != 1} { - return -code error "wrong number of arguments" - } + if {[llength $args] != 1} { + return -code error "wrong number of arguments" + } - # Add to new parent - node insertBefore $token [lindex $args 0] + # Add to new parent + node insertBefore $token [lindex $args 0] - } + } - hasChildNodes { - set result [Min 1 [llength [set $node(node:childNodes)]]] - } + hasChildNodes { + set result [Min 1 [llength [set $node(node:childNodes)]]] + } - cl* { - # cloneNode + cl* { + # cloneNode - set deep 0 - switch [llength $args] { - 0 { - } - 1 { - set deep [Boolean [lindex $args 0]] - } - default { - return -code error "too many arguments" - } - } + set deep 0 + switch [llength $args] { + 0 { + } + 1 { + set deep [Boolean [lindex $args 0]] + } + default { + return -code error "too many arguments" + } + } - switch -- $node(node:nodeType) { - element { - set result [CreateElement {} $node(node:nodeName) [array get $node(element:attributeList)] -docarray $node(docArray)] - if {$deep} { - foreach child [set $node(node:childNodes)] { - node appendChild $result [node cloneNode $child] - } - } - } - textNode { - set result [CreateTextNode {} $node(node:nodeValue) -docarray $node(docArray)] - } - document - - documentFragment - - default { - set result [CreateGeneric {} node:nodeType $node(node:nodeType) -docarray $node(docArray)] - if {$deep} { - foreach child [set $node(node:childNodes)] { - node appendChild $result [node cloneNode $child] - } - } - } - } + switch -- $node(node:nodeType) { + element { + set result [CreateElement {} $node(node:nodeName) [array get $node(element:attributeList)] -docarray $node(docArray)] + if {$deep} { + foreach child [set $node(node:childNodes)] { + node appendChild $result [node cloneNode $child] + } + } + } + textNode { + set result [CreateTextNode {} $node(node:nodeValue) -docarray $node(docArray)] + } + document - + documentFragment - + default { + set result [CreateGeneric {} node:nodeType $node(node:nodeType) -docarray $node(docArray)] + if {$deep} { + foreach child [set $node(node:childNodes)] { + node appendChild $result [node cloneNode $child] + } + } + } + } - } + } - ch* { - # children -- non-standard method + ch* { + # children -- non-standard method - # If this is a textNode, then catch the error - set result {} - catch {set result [set $node(node:childNodes)]} + # If this is a textNode, then catch the error + set result {} + catch {set result [set $node(node:childNodes)]} - } + } - pa* { - # parent -- non-standard method + pa* { + # parent -- non-standard method - return $node(node:parentNode) + return $node(node:parentNode) - } + } - default { - return -code error "unknown method \"$method\"" - } + default { + return -code error "unknown method \"$method\"" + } } @@ -1105,23 +1105,23 @@ # Create new node if {![info exists opts(-id)]} { - set opts(-id) node[incr docArray(counter)] + set opts(-id) node[incr docArray(counter)] } set docArray($opts(-id)) [list id $opts(-id) \ - docArray $parent(docArray) \ - node:parentNode $opts(-parent) \ - node:childNodes $parent(docArray)var$docArray(counter) \ - node:nodeType $opts(-type) \ - node:nodeName $opts(-name) \ - node:nodeValue $opts(-value) \ - element:attributeList $parent(docArray)arr$docArray(counter) \ + docArray $parent(docArray) \ + node:parentNode $opts(-parent) \ + node:childNodes $parent(docArray)var$docArray(counter) \ + node:nodeType $opts(-type) \ + node:nodeName $opts(-name) \ + node:nodeValue $opts(-value) \ + element:attributeList $parent(docArray)arr$docArray(counter) \ ] set $parent(docArray)var$docArray(counter) {} array set $parent(docArray)arr$docArray(counter) {} # Update parent node if {![info exists parent(document:documentElement)]} { - lappend parent(node:childNodes) [list [lindex $opts(-parent) 0] $opts(-id)] + lappend parent(node:childNodes) [list [lindex $opts(-parent) 0] $opts(-id)] } return $parent(docArray)($opts(-id)) @@ -1143,7 +1143,7 @@ upvar $token node foreach {key value} $args { - set node($key) $value + set node($key) $value } set $token [array get node] @@ -1178,111 +1178,111 @@ switch -- $method { - cget { - # Some read-only configuration options are computed - if {[llength $args] != 1} { - return -code error "too many arguments" - } - if {[regexp [format {^-(%s)$} $elementOptionsRO] [lindex $args 0] discard option]} { - switch -- $option { - tagName { - set result [lindex $node(node:nodeName) 0] - } - empty { - if {![info exists node(element:empty)]} { - return 0 - } else { - return $node(element:empty) - } - } - default { - return $node(node:$option) - } - } - } elseif {[regexp [format {^-(%s)$} $elementOptionsRW] [lindex $args 0] discard option]} { - return $node(node:$option) - } else { - return -code error "unknown option \"[lindex $args 0]\"" - } - } - configure { - if {[llength $args] == 1} { - return [document cget $token [lindex $args 0]] - } elseif {[llength $args] % 2} { - return -code error "no value specified for option \"[lindex $args end]\"" - } else { - foreach {option value} $args { - if {[regexp [format {^-(%s)$} $elementOptionsRO] $option discard opt]} { - return -code error "attribute \"$option\" is read-only" - } elseif {[regexp [format {^-(%s)$} $elementOptionsRW] $option discard opt]} { - return -code error "not implemented" - } else { - return -code error "unknown option \"$option\"" - } - } - } - } + cget { + # Some read-only configuration options are computed + if {[llength $args] != 1} { + return -code error "too many arguments" + } + if {[regexp [format {^-(%s)$} $elementOptionsRO] [lindex $args 0] discard option]} { + switch -- $option { + tagName { + set result [lindex $node(node:nodeName) 0] + } + empty { + if {![info exists node(element:empty)]} { + return 0 + } else { + return $node(element:empty) + } + } + default { + return $node(node:$option) + } + } + } elseif {[regexp [format {^-(%s)$} $elementOptionsRW] [lindex $args 0] discard option]} { + return $node(node:$option) + } else { + return -code error "unknown option \"[lindex $args 0]\"" + } + } + configure { + if {[llength $args] == 1} { + return [document cget $token [lindex $args 0]] + } elseif {[llength $args] % 2} { + return -code error "no value specified for option \"[lindex $args end]\"" + } else { + foreach {option value} $args { + if {[regexp [format {^-(%s)$} $elementOptionsRO] $option discard opt]} { + return -code error "attribute \"$option\" is read-only" + } elseif {[regexp [format {^-(%s)$} $elementOptionsRW] $option discard opt]} { + return -code error "not implemented" + } else { + return -code error "unknown option \"$option\"" + } + } + } + } - getAttribute { - if {[llength $args] != 1} { - return -code error "wrong number of arguments" - } + getAttribute { + if {[llength $args] != 1} { + return -code error "wrong number of arguments" + } - upvar #0 $node(element:attributeList) attrList - catch {set result $attrList([lindex $args 0])} + upvar #0 $node(element:attributeList) attrList + catch {set result $attrList([lindex $args 0])} - } + } - setAttribute { - if {[llength $args] == 0 || [llength $args] > 2} { - return -code error "wrong number of arguments" - } + setAttribute { + if {[llength $args] == 0 || [llength $args] > 2} { + return -code error "wrong number of arguments" + } - # TODO: Check that the attribute name is legal + # TODO: Check that the attribute name is legal - upvar #0 $node(element:attributeList) attrList - set attrList([lindex $args 0]) [lindex $args 1] + upvar #0 $node(element:attributeList) attrList + set attrList([lindex $args 0]) [lindex $args 1] - } + } - removeAttribute { - if {[llength $args] != 1} { - return -code error "wrong number of arguments" - } + removeAttribute { + if {[llength $args] != 1} { + return -code error "wrong number of arguments" + } - upvar #0 $node(element:attributeList) attrList - unset -nocomplain attrList([lindex $args 0]) + upvar #0 $node(element:attributeList) attrList + unset -nocomplain attrList([lindex $args 0]) - } + } - getAttributeNode { - } + getAttributeNode { + } - setAttributeNode { - } + setAttributeNode { + } - removeAttributeNode { - } + removeAttributeNode { + } - getElementsByTagName { - if {[llength $args] != 1} { - return -code error "wrong number of arguments" - } + getElementsByTagName { + if {[llength $args] != 1} { + return -code error "wrong number of arguments" + } - return [Element:GetByTagName $token [lindex $args 0]] - } + return [Element:GetByTagName $token [lindex $args 0]] + } - normalize { - if {[llength $args]} { - return -code error "wrong number of arguments" - } + normalize { + if {[llength $args]} { + return -code error "wrong number of arguments" + } - Element:Normalize node [set $node(node:childNodes)] - } + Element:Normalize node [set $node(node:childNodes)] + } - default { - return -code error "unknown method \"$method\"" - } + default { + return -code error "unknown method \"$method\"" + } } @@ -1309,22 +1309,22 @@ set result {} if {$node(node:nodeType) ne "documentFragment" } { - foreach child [set $node(node:childNodes)] { - unset -nocomplain childNode - array set childNode [set $child] - if {$childNode(node:nodeType) eq "element" - && [GetField childNode(node:nodeName)] eq $name - } { - lappend result $child - } - } + foreach child [set $node(node:childNodes)] { + unset -nocomplain childNode + array set childNode [set $child] + if {$childNode(node:nodeType) eq "element" + && [GetField childNode(node:nodeName)] eq $name + } { + lappend result $child + } + } } elseif {[llength $node(document:documentElement)]} { - # Document Element must exist and must be an element type node - unset -nocomplain childNode - array set childNode [set $node(document:documentElement)] - if {$childNode(node:nodeName) eq $name } { - set result $node(document:documentElement) - } + # Document Element must exist and must be an element type node + unset -nocomplain childNode + array set childNode [set $node(document:documentElement)] + if {$childNode(node:nodeName) eq $name } { + set result $node(document:documentElement) + } } return $result @@ -1347,40 +1347,40 @@ set textNode {} foreach n $nodes { - GetHandle node $n child - set cleanup {} + GetHandle node $n child + set cleanup {} - switch -- $child(node:nodeType) { - textNode { - if {[llength $textNode]} { - # Coalesce into previous node - append text(node:nodeValue) $child(node:nodeValue) - # Remove this child - upvar #0 $parent(node:childNodes) childNodes - set idx [lsearch $childNodes $n] - set childNodes [lreplace $childNodes $idx $idx] - unset $n - set cleanup {} + switch -- $child(node:nodeType) { + textNode { + if {[llength $textNode]} { + # Coalesce into previous node + append text(node:nodeValue) $child(node:nodeValue) + # Remove this child + upvar #0 $parent(node:childNodes) childNodes + set idx [lsearch $childNodes $n] + set childNodes [lreplace $childNodes $idx $idx] + unset $n + set cleanup {} - PutHandle $textNode text - } else { - set textNode $n - unset -nocomplain text - array set text [array get child] - } - } - element - - document - - documentFragment { - set textNode {} - Element:Normalize child [set $child(node:childNodes)] - } - default { - set textNode {} - } - } + PutHandle $textNode text + } else { + set textNode $n + unset -nocomplain text + array set text [array get child] + } + } + element - + document - + documentFragment { + set textNode {} + Element:Normalize child [set $child(node:childNodes)] + } + default { + set textNode {} + } + } - eval $cleanup + eval $cleanup } return {} @@ -1413,61 +1413,61 @@ switch -- $method { - cget { - # Some read-only configuration options are computed - if {[llength $args] != 1} { - return -code error "too many arguments" - } - if {[regexp [format {^-(%s)$} $elementOptionsRO] [lindex $args 0] discard option]} { - switch -- $option { - target { - set result [lindex $node(node:nodeName) 0] - } - default { - return $node(node:$option) - } - } - } elseif {[regexp [format {^-(%s)$} $elementOptionsRW] [lindex $args 0] discard option]} { - switch -- $option { - data { - return $node(node:nodeValue) - } - default { - return $node(node:$option) - } - } - } else { - return -code error "unknown option \"[lindex $args 0]\"" - } - } - configure { - if {[llength $args] == 1} { - return [document cget $token [lindex $args 0]] - } elseif {[llength $args] % 2} { - return -code error "no value specified for option \"[lindex $args end]\"" - } else { - foreach {option value} $args { - if {[regexp [format {^-(%s)$} $elementOptionsRO] $option discard opt]} { - return -code error "attribute \"$option\" is read-only" - } elseif {[regexp [format {^-(%s)$} $elementOptionsRW] $option discard opt]} { - switch -- $opt { - data { - set node(node:nodeValue) $value - } - default { - set node(node:$opt) $value - } - } - } else { - return -code error "unknown option \"$option\"" - } - } - } - } + cget { + # Some read-only configuration options are computed + if {[llength $args] != 1} { + return -code error "too many arguments" + } + if {[regexp [format {^-(%s)$} $elementOptionsRO] [lindex $args 0] discard option]} { + switch -- $option { + target { + set result [lindex $node(node:nodeName) 0] + } + default { + return $node(node:$option) + } + } + } elseif {[regexp [format {^-(%s)$} $elementOptionsRW] [lindex $args 0] discard option]} { + switch -- $option { + data { + return $node(node:nodeValue) + } + default { + return $node(node:$option) + } + } + } else { + return -code error "unknown option \"[lindex $args 0]\"" + } + } + configure { + if {[llength $args] == 1} { + return [document cget $token [lindex $args 0]] + } elseif {[llength $args] % 2} { + return -code error "no value specified for option \"[lindex $args end]\"" + } else { + foreach {option value} $args { + if {[regexp [format {^-(%s)$} $elementOptionsRO] $option discard opt]} { + return -code error "attribute \"$option\" is read-only" + } elseif {[regexp [format {^-(%s)$} $elementOptionsRW] $option discard opt]} { + switch -- $opt { + data { + set node(node:nodeValue) $value + } + default { + set node(node:$opt) $value + } + } + } else { + return -code error "unknown option \"$option\"" + } + } + } + } - default { - return -code error "unknown method \"$method\"" - } + default { + return -code error "unknown method \"$method\"" + } } @@ -1497,13 +1497,13 @@ array set node [set $token] if {"node1" ne $node(documentFragment:masterDoc) } { - return [eval [list Serialize:node $token] $args] + return [eval [list Serialize:node $token] $args] } else { - if {{} ne [GetField node(document:documentElement)] } { - return [eval Serialize:document [list $token] $args] - } else { - return -code error "document has no document element" - } + if {{} ne [GetField node(document:documentElement)] } { + return [eval Serialize:document [list $token] $args] + } else { + return -code error "document has no document element" + } } } @@ -1523,20 +1523,20 @@ array set node [set $token] if {![info exists node(document:documentElement)]} { - return -code error "document has no document element" + return -code error "document has no document element" } elseif {$node(document:doctype) eq ""} { - return -code error "no document type declaration given" + return -code error "no document type declaration given" } else { - array set doctype [set $node(document:doctype)] + array set doctype [set $node(document:doctype)] - # BUG: Want to serialize all children except for the - # document element, and then do the document element. + # BUG: Want to serialize all children except for the + # document element, and then do the document element. - # Bug fix: can't use Serialize:attributeList for XML declaration, - # since attributes must occur in a given order (XML 2.8 [23]) + # Bug fix: can't use Serialize:attributeList for XML declaration, + # since attributes must occur in a given order (XML 2.8 [23]) - return "\n\n[eval Serialize:element [list $node(document:documentElement)] $args]" + return "\n\n[eval Serialize:element [list $node(document:documentElement)] $args]" } } @@ -1555,7 +1555,7 @@ set result {} foreach ident $id { - append result { } \"$ident\" + append result { } \"$ident\" } return $result @@ -1576,11 +1576,11 @@ proc dom::Serialize:XMLDecl {attr attrList} { array set data $attrList if {![info exists data($attr)]} { - return {} + return {} } elseif {[string length $data($attr)]} { - return " $attr='$data($attr)'" + return " $attr='$data($attr)'" } else { - return {} + return {} } } @@ -1601,9 +1601,9 @@ set result {} foreach childToken [set $node(node:childNodes)] { - unset -nocomplain child - array set child [set $childToken] - append result [eval [list Serialize:$child(node:nodeType) $childToken] $args] + unset -nocomplain child + array set child [set $childToken] + append result [eval [list Serialize:$child(node:nodeType) $childToken] $args] } return $result @@ -1628,24 +1628,24 @@ set result {} set newline {} if {[lsearch $opts(-newline) $node(node:nodeName)] >= 0} { - append result \n - set newline \n + append result \n + set newline \n } append result "<$node(node:nodeName)" append result [Serialize:attributeList [array get $node(element:attributeList)]] if {![llength [set $node(node:childNodes)]]} { - append result />$newline + append result />$newline } else { - append result >$newline + append result >$newline - # Do the children - append result [eval Serialize:node [list $token] $args] + # Do the children + append result [eval Serialize:node [list $token] $args] - append result "$newline$newline" + append result "$newline$newline" } @@ -1715,12 +1715,12 @@ proc dom::Encode value { array set Entity { - $ $ - < < - > > - & & - \" " - ' ' + $ $ + < < + > > + & & + \" " + ' ' } regsub -all -- {([$<>&"'])} $value {$Entity(\1)} value @@ -1743,19 +1743,19 @@ set result {} foreach {name value} $l { - append result { } $name = + append result { } $name = - # Handle special characters - regsub -all < $value {\<} value + # Handle special characters + regsub -all < $value {\<} value - if {![string match "*\"*" $value]} { - append result \"$value\" - } elseif {![string match "*'*" $value]} { - append result '$value' - } else { - regsub -all \" $value {\"} value - append result \"$value\" - } + if {![string match "*\"*" $value]} { + append result \"$value\" + } elseif {![string match "*'*" $value]} { + append result '$value' + } else { + regsub -all \" $value {\"} value + append result \"$value\" + } } @@ -1786,20 +1786,20 @@ array set opts $args lappend state(current) \ - [CreateElement [lindex $state(current) end] $name $attrList] + [CreateElement [lindex $state(current) end] $name $attrList] if {[info exists opts(-empty)] && $opts(-empty)} { - # Flag this node as being an empty element - array set node [set [lindex $state(current) end]] - set node(element:empty) 1 - set [lindex $state(current) end] [array get node] + # Flag this node as being an empty element + array set node [set [lindex $state(current) end]] + set node(element:empty) 1 + set [lindex $state(current) end] [array get node] } # Temporary: implement -progresscommand here, because of broken parser if {[string length $state(-progresscommand)]} { - if {!([incr state(progCounter)] % $state(-chunksize))} { - uplevel #0 $state(-progresscommand) - } + if {!([incr state(progCounter)] % $state(-chunksize))} { + uplevel #0 $state(-progresscommand) + } } } @@ -1876,8 +1876,8 @@ array set xmldecl $node(document:xmldecl) array set xmldecl [list version $version \ - standalone $standalone \ - encoding $encoding \ + standalone $standalone \ + encoding $encoding \ ] set node(document:xmldecl) [array get xmldecl] @@ -1930,17 +1930,17 @@ switch -- $node(node:nodeType) { - textNode { - if {[string trim $node(node:nodeValue)] eq ""} { - node removeChild $node(node:parentNode) $nodeid - } - } + textNode { + if {[string trim $node(node:nodeValue)] eq ""} { + node removeChild $node(node:parentNode) $nodeid + } + } - default { - foreach child [set $node(node:childNodes)] { - Trim $child - } - } + default { + foreach child [set $node(node:childNodes)] { + Trim $child + } + } }