File: domnamespace.test

package info (click to toggle)
tdom 0.9.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 7,260 kB
  • sloc: ansic: 56,762; xml: 20,797; tcl: 3,618; sh: 658; makefile: 83; cpp: 30
file content (388 lines) | stat: -rw-r--r-- 14,763 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
# Features covered: Namespace related DOM actions.
#
# This file contains a collection of tests for some namespace related
# actions.
#
#    domnamespace-1.*: misc tests
#    domnamespace-2.*: moving namespaced nodes from one document to another
#    domnamespace-3.*: moving namespaced nodes within a document
#    domnamespace-4.*: createNodeCmd and namespaces
#
# Copyright (c) 2002 Rolf Ade.
#
# RCS: @(#) $Id$

source [file join [file dir [info script]] loadtdom.tcl]

test domnamespace-1.1 {multiple definition of the same namespace (same prefix/uri)} {
    set ch [open [file join [pwd] [file dir [info script]] data/REC-xslt-19991116.xml]]
    fconfigure $ch -encoding iso8859-1
    set doc [dom parse -channel $ch]
    set root [$doc documentElement]
    set nodes [$root selectNodes //e:element-syntax]
    $doc delete
    llength $nodes
} {35}

test domnamespace-1.2 {more than 128 different namespaces in one doc} {
    set doc [dom parse {
        <root xmlns:n0="n0" xmlns:n1="n1" xmlns:n2="n2" xmlns:n3="n3"
        xmlns:n4="n4" xmlns:n5="n5" xmlns:n6="n6" xmlns:n7="n7"
        xmlns:n8="n8" xmlns:n9="n9" xmlns:n10="n10" xmlns:n11="n11"
        xmlns:n12="n12" xmlns:n13="n13" xmlns:n14="n14"
        xmlns:n15="n15" xmlns:n16="n16" xmlns:n17="n17"
        xmlns:n18="n18" xmlns:n19="n19" xmlns:n20="n20"
        xmlns:n21="n21" xmlns:n22="n22" xmlns:n23="n23"
        xmlns:n24="n24" xmlns:n25="n25" xmlns:n26="n26"
        xmlns:n27="n27" xmlns:n28="n28" xmlns:n29="n29"
        xmlns:n30="n30" xmlns:n31="n31" xmlns:n32="n32"
        xmlns:n33="n33" xmlns:n34="n34" xmlns:n35="n35"
        xmlns:n36="n36" xmlns:n37="n37" xmlns:n38="n38"
        xmlns:n39="n39" xmlns:n40="n40" xmlns:n41="n41"
        xmlns:n42="n42" xmlns:n43="n43" xmlns:n44="n44"
        xmlns:n45="n45" xmlns:n46="n46" xmlns:n47="n47"
        xmlns:n48="n48" xmlns:n49="n49" xmlns:n50="n50"
        xmlns:n51="n51" xmlns:n52="n52" xmlns:n53="n53"
        xmlns:n54="n54" xmlns:n55="n55" xmlns:n56="n56"
        xmlns:n57="n57" xmlns:n58="n58" xmlns:n59="n59"
        xmlns:n60="n60" xmlns:n61="n61" xmlns:n62="n62"
        xmlns:n63="n63" xmlns:n64="n64" xmlns:n65="n65"
        xmlns:n66="n66" xmlns:n67="n67" xmlns:n68="n68"
        xmlns:n69="n69" xmlns:n70="n70" xmlns:n71="n71"
        xmlns:n72="n72" xmlns:n73="n73" xmlns:n74="n74"
        xmlns:n75="n75" xmlns:n76="n76" xmlns:n77="n77"
        xmlns:n78="n78" xmlns:n79="n79" xmlns:n80="n80"
        xmlns:n81="n81" xmlns:n82="n82" xmlns:n83="n83"
        xmlns:n84="n84" xmlns:n85="n85" xmlns:n86="n86"
        xmlns:n87="n87" xmlns:n88="n88" xmlns:n89="n89"
        xmlns:n90="n90" xmlns:n91="n91" xmlns:n92="n92"
        xmlns:n93="n93" xmlns:n94="n94" xmlns:n95="n95"
        xmlns:n96="n96" xmlns:n97="n97" xmlns:n98="n98"
        xmlns:n99="n99" xmlns:n100="n100" xmlns:n101="n101"
        xmlns:n102="n102" xmlns:n103="n103" xmlns:n104="n104"
        xmlns:n105="n105" xmlns:n106="n106" xmlns:n107="n107"
        xmlns:n108="n108" xmlns:n109="n109" xmlns:n110="n110"
        xmlns:n111="n111" xmlns:n112="n112" xmlns:n113="n113"
        xmlns:n114="n114" xmlns:n115="n115" xmlns:n116="n116"
        xmlns:n117="n117" xmlns:n118="n118" xmlns:n119="n119"
        xmlns:n120="n120" xmlns:n121="n121" xmlns:n122="n122"
        xmlns:n123="n123" xmlns:n124="n124" xmlns:n125="n125"
        xmlns:n126="n126" xmlns:n127="n127" xmlns:n128="n128"
        xmlns:n129="n129"><n0:e/><n129:e/></root>}]
    $doc documentElement root
    set result [[$root firstChild] namespace]
    lappend result [[$root lastChild] namespace]
    $doc delete
    set result
} {n0 n129}

test domnamespace-2.1 {moving namespaced nodes between documents} {
    set doc1 [dom parse {<root xmlns="NS1"><doc1elem/></root>}]
    set root1 [$doc1 documentElement]
    set doc2 [dom parse {<root xmlns="NS2"/>}]
    set root2 [$doc2 documentElement]
    
    $root2 appendChild [$root1 firstChild]
    set result [$root2 asXML -indent none]
    $doc1 delete
    $doc2 delete
    set result
} {<root xmlns="NS2"><doc1elem xmlns="NS1"/></root>}

test domnamespace-2.2 {moving namespaced nodes between documents} {
    set doc1 [dom parse {<root xmlns="NS1"><doc1elem/></root>}]
    set root1 [$doc1 documentElement]
    set doc2 [dom parse {<root xmlns="NS2"/>}]
    set root2 [$doc2 documentElement]
    
    set node [$root1 removeChild [$root1 firstChild]]
    $root2 appendChild $node
    set result [$root2 asXML -indent none]
    $doc1 delete
    $doc2 delete
    set result
} {<root xmlns="NS2"><doc1elem xmlns="NS1"/></root>}

test domnamespace-2.3 {moving namespaced nodes between documents} {
    set doc1 [dom parse {<root xmlns="NS1"><doc1elem><a/></doc1elem></root>}]
    set root1 [$doc1 documentElement]
    set doc2 [dom parse {<root xmlns="NS2"/>}]
    set root2 [$doc2 documentElement]
    
    set node [$root1 removeChild [$root1 firstChild]]
    $root2 appendChild $node
    set result [$root2 asXML -indent none]
    $doc1 delete
    $doc2 delete
    set result
} {<root xmlns="NS2"><doc1elem xmlns="NS1"><a/></doc1elem></root>}

test domnamespace-2.4 {moving namespaced nodes between documents} {
    set doc1 [dom parse {<root><doc1elem><a/></doc1elem></root>}]
    set root1 [$doc1 documentElement]
    set doc2 [dom parse {<root xmlns="NS2"/>}]
    set root2 [$doc2 documentElement]
    
    set node [$root1 removeChild [$root1 firstChild]]
    $root2 appendChild $node
    set result [$root2 asXML -indent none]
    $doc1 delete
    $doc2 delete
    set result
} {<root xmlns="NS2"><doc1elem xmlns=""><a/></doc1elem></root>}

test domnamespace-2.5 {moving namespaced nodes between documents} {
    set doc1 [dom parse {<root><doc1elem><a/></doc1elem></root>}]
    set root1 [$doc1 documentElement]
    set doc2 [dom parse {<root xmlns="NS2"/>}]
    set root2 [$doc2 documentElement]
    
    set node [$root1 removeChild [$root1 firstChild]]
    $root2 appendChild $node
    set result [llength [$root2 getElementsByTagNameNS "" *]]
    $doc1 delete
    $doc2 delete
    set result
} {2}

test domnamespace-2.6 {moving namespaced nodes between documents} {
    set doc1 [dom parse {<root xmlns="NS2"><doc1elem><a/></doc1elem></root>}]
    set root1 [$doc1 documentElement]
    set doc2 [dom parse {<root xmlns="NS2"/>}]
    set root2 [$doc2 documentElement]

    set node [$root1 removeChild [$root1 firstChild]]
    $root2 appendChild $node
    set result [$root2 asXML -indent none]
    $doc1 delete
    $doc2 delete
    set result
} {<root xmlns="NS2"><doc1elem><a/></doc1elem></root>}

test domnamespace-2.7 {moving namespaced nodes between documents} {
    set doc1 [dom parse {<root xmlns="NS2"><doc1elem><a/></doc1elem></root>}]
    set root1 [$doc1 documentElement]
    set doc2 [dom parse {<root xmlns="NS2"/>}]
    set root2 [$doc2 documentElement]

    $root2 appendChild [[$root1 firstChild] cloneNode -deep]
    set result [$root2 asXML -indent none]
    $doc1 delete
    $doc2 delete
    set result
} {<root xmlns="NS2"><doc1elem><a/></doc1elem></root>}

test domnamespace-2.8 {moving namespaced nodes between documents} {
    set doc1 [dom parse {<root xmlns="NS2"><doc1elem><a/></doc1elem></root>}]
    set root1 [$doc1 documentElement]
    set doc2 [dom parse {<root xmlns="NS2"/>}]
    set root2 [$doc2 documentElement]

    $root2 appendChild [$root1 firstChild]
    set result [$root2 asXML -indent none]
    $doc1 delete
    $doc2 delete
    set result
} {<root xmlns="NS2"><doc1elem><a/></doc1elem></root>}

test domnamespace-2.9 {moving namespaced nodes between documents} {
    set doc1 [dom parse {<root xmlns="NS2"><doc1elem><a/></doc1elem></root>}]
    set root1 [$doc1 documentElement]
    set doc2 [dom parse {<root xmlns:p="NS2"/>}]
    set root2 [$doc2 documentElement]

    $root2 appendChild [$root1 firstChild]
    set result [$root2 asXML -indent none]
    $doc1 delete
    $doc2 delete
    set result
} {<root xmlns:p="NS2"><doc1elem xmlns="NS2"><a/></doc1elem></root>}

test domnamespace-2.10 {moving nodes with attributes between documents} {
    set doc1 [dom parse {<root><doc1elem><a b="c"/></doc1elem></root>}]
    set root1 [$doc1 documentElement]
    set doc2 [dom parse {<root xmlns="NS2"/>}]
    set root2 [$doc2 documentElement]

    set node [$root1 removeChild [$root1 firstChild]]
    $root2 appendChild $node
    set result [$root2 asXML -indent none]
    $doc1 delete
    $doc2 delete
    set result
} {<root xmlns="NS2"><doc1elem xmlns=""><a b="c"/></doc1elem></root>}

test domnamespace-2.11 {moving nodes with namespaced attributes between documents} {
    set doc1 [dom parse {<root xmlns:p="foo"><doc1elem><a p:b="c"/></doc1elem></root>}]
    set root1 [$doc1 documentElement]
    set doc2 [dom parse {<root xmlns="NS2"/>}]
    set root2 [$doc2 documentElement]

    set node [$root1 removeChild [$root1 firstChild]]
    $root2 appendChild $node
    set result [$root2 asXML -indent none]
    $doc1 delete
    $doc2 delete
    set result
} {<root xmlns="NS2"><doc1elem xmlns=""><a xmlns:p="foo" p:b="c"/></doc1elem></root>}

test domnamespace-2.12 {moving nodes with namespaced attributes between documents} {
    set doc1 [dom parse {<root xmlns:p="foo"><doc1elem><a p:b="c"/></doc1elem></root>}]
    set root1 [$doc1 documentElement]
    set doc2 [dom parse {<root xmlns="NS2"/>}]
    set root2 [$doc2 documentElement]
    
    set node [$root1 removeChild [$root1 firstChild]]
    $root2 appendChild $node
    $root2 setAttributeNS "" "xmlns:p" "foo"
    set result [$root2 selectNodes {//@p:*}]
    $doc1 delete
    $doc2 delete
    set result
} {{p:b c}}

test domnamespace-2.13 {moving nodes with namespaced attributes between documents} {
    set doc1 [dom parse {<root xmlns:p="foo"><doc1elem><a p:b="c"/></doc1elem></root>}]
    set root1 [$doc1 documentElement]
    set doc2 [dom parse {<root xmlns="NS2"/>}]
    set root2 [$doc2 documentElement]
    
    set node [$root1 removeChild [$root1 firstChild]]
    $root2 setAttributeNS "" "xmlns:p" "foo"
    $root2 appendChild $node
    set result [$root2 asXML -indent none]
    $doc1 delete
    $doc2 delete
    set result
} {<root xmlns="NS2" xmlns:p="foo"><doc1elem xmlns=""><a p:b="c"/></doc1elem></root>}

test domnamespace-2.14 {moving nodes with namespaced attributes between documents} {
    set doc1 [dom parse {<root xmlns="NS1" xmlns:p="foo"><doc1elem><a p:b="c"/></doc1elem></root>}]
    set root1 [$doc1 documentElement]
    set doc2 [dom parse {<root xmlns="NS2"><e xmlns=""/></root>}]
    set root2 [$doc2 documentElement]
    
    set node [$root1 removeChild [$root1 firstChild]]
    [$root2 firstChild] appendChild $node
    set result [$root2 asXML -indent none]
    $doc1 delete
    $doc2 delete
    set result
} {<root xmlns="NS2"><e xmlns=""><doc1elem xmlns="NS1"><a xmlns:p="foo" p:b="c"/></doc1elem></e></root>}

test domnamespace-2.15 {moving nodes with namespaced attributes between documents} {
    set doc1 [dom parse {<root xmlns="NS1" xmlns:p="foo"><doc1elem><a p:b="c"/></doc1elem></root>}]
    set root1 [$doc1 documentElement]
    set doc2 [dom parse {<root xmlns="NS2"><e xmlns=""/></root>}]
    set root2 [$doc2 documentElement]
    
    set node [$root1 removeChild [$root1 firstChild]]
    [$root2 firstChild] appendChild $node
    set nodes [$doc2 getElementsByTagNameNS "NS1" *]
    catch {unset result}
    foreach node $nodes {
        lappend result [$node nodeName]
    }
    $doc1 delete
    $doc2 delete
    set result
} {doc1elem a}

test domnamespace-2.16 {It is not recommended to create attributes that look like namespace declarations} {
    set doc [[dom parse {<test xmlns="foo"/>}] documentElement]
    set child [[dom parse {<item/>}] documentElement]
    $child setAttribute xmlns "foo"
    $doc appendChild $child
    $doc asXML -indent none
} {<test xmlns="foo"><item xmlns="" xmlns="foo"/></test>}

test domnamespace-2.17 {It is not recommended to create xml namespace declarations} {
    set doc [[dom parse {<test xmlns="foo"/>}] documentElement]
    set child [[dom parse {<item/>}] documentElement]
    $child setAttributeNS "" xmlns "foo"
    $doc appendChild $child
    $doc asXML -indent none
} {<test xmlns="foo"><item xmlns="foo" xmlns=""/></test>}

test domnamespace-3.1 {moving namespaced nodes within a document} {
    set doc [dom parse {<doc><e xmlns="foo"><ee/></e><e xmlns="bar"/></doc>}]
    set root [$doc documentElement]
    set nodeToMove [$doc selectNodes {/doc/node()[1]/node()[1]}]
    set newParent [$doc selectNodes {/doc/node()[2]}]
    $newParent appendChild $nodeToMove
    set result [$doc asXML -indent none]
    $doc delete
    set result
} {<doc><e xmlns="foo"/><e xmlns="bar"><ee xmlns="foo"/></e></doc>}


namespace eval nodeCmds {
    dom createNodeCmd -namespace foo.bar elementNode ns1:e1
    dom createNodeCmd -namespace foo.bar elementNode e1
    dom createNodeCmd textNode t
    dom createNodeCmd -tagName e1 elementNode e1NoNS
}

test domnamespace-4.1 {createNodeCmd and namespace} {
    dom createDocument doc doc
    $doc documentElement root
    $root appendFromScript {
        nodeCmds::ns1:e1 {nodeCmds::t "this"}
    }
    set result [$doc asXML -indent none]
    $doc delete
    set result
} {<doc><ns1:e1 xmlns:ns1="foo.bar">this</ns1:e1></doc>}

test domnamespace-4.2 {createNodeCmd and namespace} {
    dom createDocumentNS foo.bar ns1:doc doc
    $doc documentElement root
    $root appendFromScript {
        nodeCmds::ns1:e1 {nodeCmds::t "this"}
    }
    set result [$doc asXML -indent none]
    $doc delete
    set result
} {<ns1:doc xmlns:ns1="foo.bar"><ns1:e1>this</ns1:e1></ns1:doc>}

test domnamespace-4.3 {createNodeCmd and namespace} {
    dom createDocumentNS foo.bar doc doc
    $doc documentElement root
    $root appendFromScript {
        nodeCmds::ns1:e1 {nodeCmds::t "this"}
    }
    set result [$doc asXML -indent none]
    $doc delete
    set result
} {<doc xmlns="foo.bar"><ns1:e1 xmlns:ns1="foo.bar">this</ns1:e1></doc>}

test domnamespace-4.4 {createNodeCmd and namespace} {
    dom createDocumentNS foo.bar doc doc
    $doc documentElement root
    $root appendFromScript {
        nodeCmds::e1 {
            nodeCmds::e1NoNS att attValue {nodeCmds::t "this"}
        }
    }
    set result [$doc asXML -indent none]
    $doc delete
    set result
} {<doc xmlns="foo.bar"><e1><e1 xmlns="" att="attValue">this</e1></e1></doc>}

test domnamespace-4.5 {createNodeCmd and namespace} {
    dom createDocumentNS foo.bar doc doc
    $doc documentElement root
    $root appendFromScript {
        nodeCmds::e1 {
            nodeCmds::e1NoNS att attValue {nodeCmds::t "this"}
        }
    }
    set result [$doc selectNodes -namespaces {fb foo.bar} string(/fb:doc/fb:e1/e1/@att)]
    $doc delete
    set result
} {attValue}

    
# cleanup
::tcltest::cleanupTests
return