1 // makeswf -v 7 -r 1 -o xml-node-7.swf xml-node.as
5 // Test XMLNode issues that are not handled by xml-parse test
7 function test_childNodes
()
9 var x
= new XML ("<root><a/><b/>c<d/></root>");
10 var root
= x
.firstChild
;
14 trace
(root
.childNodes
);
16 // add fake elements to childNodes array and test what methods reset the array
17 root
.childNodes
.push
("fake");
18 trace
(root
.childNodes
);
19 root
.firstChild
.removeNode
();
20 trace
(root
.childNodes
);
21 root
.childNodes
.push
(new XMLNode (1, "fake"));
22 trace
(root
.childNodes
);
23 root
.appendChild
(new XMLNode (1, "e"));
24 trace
(root
.childNodes
);
25 ASSetPropFlags
(root
.childNodes
, "0", 0, 4); // remove write-protection
26 root
.childNodes
[0] = new XMLNode (3, "fake");
27 trace
(root
.childNodes
);
28 root
.insertBefore
(new XMLNode (1, "f"), root
.lastChild
);
29 trace
(root
.childNodes
);
32 function test_references
()
34 var x
= new XML ("<parent><previoussibling/><root><firstchild/><middlechild/><lastchild/></root><nextsibling/></parent>");
35 var root
= x
.firstChild
.firstChild
.nextSibling
;
38 trace
(root
.parentNode
.nodeName
);
39 trace
(root
.firstChild
.nodeName
);
40 trace
(root
.lastChild
.nodeName
);
41 trace
(root
.nextSibling
.nodeName
);
42 trace
(root
.previousSibling
.nodeName
);
43 trace
(root
.hasChildNodes
());
46 root
.parentNode
= new XMLNode (1, "test");
47 root
.firstChild
= new XMLNode (1, "test");
48 root
.lastChild
= new XMLNode (1, "test");
49 root
.nextSibling
= new XMLNode (1, "test");
50 root
.previousSibling
= new XMLNode (1, "test");
51 trace
(root
.parentNode
.nodeName
);
52 trace
(root
.firstChild
.nodeName
);
53 trace
(root
.lastChild
.nodeName
);
54 trace
(root
.nextSibling
.nodeName
);
55 trace
(root
.previousSibling
.nodeName
);
56 trace
(root
.hasChildNodes
());
59 root
= new XMLNode (1, "root");
60 trace
(root
.parentNode
);
61 trace
(root
.firstChild
);
62 trace
(root
.lastChild
);
63 trace
(root
.nextSibling
);
64 trace
(root
.previousSibling
);
65 trace
(root
.hasChildNodes
());
67 // fake elements in childNodes array
68 root
.childNodes
.push
(new XMLNode (1, "fake"));
69 trace
(root
.parentNode
);
70 trace
(root
.firstChild
);
71 trace
(root
.lastChild
);
72 trace
(root
.nextSibling
);
73 trace
(root
.previousSibling
);
74 trace
(root
.hasChildNodes
());
77 function test_cloneNode
()
79 var x
= new XML ("<root><a/><b/>c<d/></root>");
80 var root
= x
.firstChild
;
83 var root2
= root
.cloneNode
();
84 trace
(root2
.childNodes
);
85 root2
= root
.cloneNode
(false);
86 trace
(root2
.childNodes
);
87 root2
= root
.cloneNode
(true);
88 trace
(root2
.childNodes
);
90 // fake elements in childNodes array
91 root
.childNodes
.push
(new XMLNode (1, "fake"));
92 root2
= root
.cloneNode
(true);
93 trace
(root2
.childNodes
);
96 function test_nodeName
()
98 var a
= new XMLNode (1, "a:b");
108 // these are read-only
119 var testvalues
= ["", ":", ":b", "a:", "a::b", "a::", "::b", "::" ];
120 testvalues
= testvalues
.concat
(values
);
121 for (var i
= 0; i
< testvalues
.length
; i
++) {
122 a
.nodeName
= testvalues
[i
];
129 function test_namespace
()
132 x
.ignoreWhite
= true;
134 <root:root xmlns='nsdefault' xmlns:a='nsa'>
135 <child xmlns='nsdefault_at_child' xmlns:d='nsd'>
144 var root
= x
.firstChild
;
147 var ele
= root
.firstChild
.firstChild
;
148 trace
(ele
.namespaceURI
);
149 trace
(ele
.getNamespaceForPrefix
());
150 trace
(ele
.getNamespaceForPrefix
(""));
151 trace
(ele
.getNamespaceForPrefix
("a"));
152 ele
= ele
.nextSibling
;
153 trace
(ele
.namespaceURI
);
154 trace
(ele
.getNamespaceForPrefix
());
155 trace
(ele
.getNamespaceForPrefix
(""));
156 trace
(ele
.getNamespaceForPrefix
("a"));
157 ele
= root
.lastChild
.previousSibling
;
158 trace
(ele
.namespaceURI
);
159 trace
(ele
.getNamespaceForPrefix
());
160 trace
(ele
.getNamespaceForPrefix
(""));
161 trace
(ele
.getNamespaceForPrefix
("a"));
162 ele
= ele
.nextSibling
;
163 trace
(ele
.namespaceURI
);
164 trace
(ele
.getNamespaceForPrefix
());
165 trace
(ele
.getNamespaceForPrefix
(""));
166 trace
(ele
.getNamespaceForPrefix
("a"));
169 ele
= root
.firstChild
.firstChild
;
170 ele
.namespaceURI
= "fake";
171 trace
(ele
.namespaceURI
);
174 function trace_attributes
(attrs
)
176 var props
= new Array ();
177 for (var prop
in attrs
) {
182 for (var i
= 0; i
< props
.length
; i
++) {
184 str
+= "&" + prop
+ "=" + attrs
[prop
];
186 trace
(str
.substr
(1));
189 function test_attributes
()
191 var x
= new XML ("<root a='a' b='b' c='' &='&' g='&'/>");
192 var root
= x
.firstChild
;
195 trace_attributes
(root
.attributes
);
196 root
.attributes
["d"] = "d";
197 trace_attributes
(root
.attributes
);
198 root
.attributes
["a"] = "A";
199 trace_attributes
(root
.attributes
);
200 delete root
.attributes
["b"];
201 trace_attributes
(root
.attributes
);
204 root
.attributes
["'"] = "'";
205 root
.attributes
["\""] = "\"";
206 root
.attributes
["&"] = "&";
207 root
.attributes
["&"] = "&";
208 trace_attributes
(root
.attributes
);
211 function test_modify
()
213 var x
= new XML ("<root><a/><b/>c<d/></root>");
214 var root
= x
.firstChild
;
222 x
.appendChild
(root
);
225 root
.insertBefore
(new XMLNode (1, "f"));
227 root
.insertBefore
(new XMLNode (1, "f"), root
.lastChild
);
229 root
.appendChild
(new XMLNode (1, "g"), new XMLNode (1, "h"));
233 root
.appendChild
(root
.firstChild
);
235 root
.insertBefore
(root
.lastChild
, root
.lastChild
);
237 root
.appendChild
(root
);
238 trace
(root
.lastChild
.nodeName
);
239 root
.firstChild
.appendChild
(root
);
240 trace
(root
.firstChild
.parentNode
.nodeName
);
241 trace
(root
.firstChild
.lastChild
.nodeName
);
244 function test_constructor
()
247 trace
(new XMLNode (1, "name"));
248 trace
(new XMLNode (3, "value"));
250 for (var i
= 0; i
< values
.length
; i
++) {
251 trace
("Creating with: " + names
[i
]);
252 trace
(new XMLNode (1, values
[i
]));
253 trace
(new XMLNode (3, values
[i
]));
254 trace
(new XMLNode (values
[i
], "value"));
267 loadMovie
("FSCommand:quit", "");