
XML.appendChild()
449
Description
Method; appends the specified node to the XML object’s child list. This method operates directly
on the node referenced by the
childNode
parameter; it does not append a copy of the node. If the
node to be appended already exists in another tree structure, appending the node to the new
location will remove it from its current location. If the
childNode
parameter refers to a node that
already exists in another XML tree structure, the appended child node is placed in the new tree
structure after it is removed from its existing parent node.
Example
This example does the following things in the order shown:
•
Creates two empty XML documents,
doc1
and
doc2
.
•
Creates a new node using the
createElement()
method, and appends it, using the
appendChild()
method, to the XML document named
doc1
.
•
Shows how to move a node using the
appendChild()
method, by moving the root node from
doc1
to
doc2
.
•
Clones the root node from
doc2
and appends it to
doc1
.
•
Creates a new node and appends it to the root node of the XML document doc1.
var doc1:XML = new XML();
var doc2:XML = new XML();
// create a root node and add it to doc1
var rootnode:XMLNode = doc1.createElement("root");
doc1.appendChild(rootnode);
trace ("doc1: " + doc1); // output: doc1: <root />
trace ("doc2: " + doc2); // output: doc2:
// move the root node to doc2
doc2.appendChild(rootnode);
trace ("doc1: " + doc1); // output: doc1:
trace ("doc2: " + doc2); // output: doc2: <root />
// clone the root node and append it to doc1
var clone:XMLNode = doc2.firstChild.cloneNode(true);
doc1.appendChild(clone);
trace ("doc1: " + doc1); // output: doc1: <root />
trace ("doc2: " + doc2); // output: doc2: <root />
// create a new node to append to root node (named clone) of doc1
var newNode:XMLNode = doc1.createElement("newbie");
clone.appendChild(newNode);
trace ("doc1: " + doc1); // output: doc1: <root><newbie /></root>
Содержание FLEX-FLEX ACTIONSCRIPT LANGUAGE
Страница 1: ...Flex ActionScript Language Reference...
Страница 8: ......
Страница 66: ...66 Chapter 2 Creating Custom Classes with ActionScript 2 0...
Страница 76: ......
Страница 133: ...break 133 See also for for in do while while switch case continue throw try catch finally...
Страница 135: ...case 135 See also break default strict equality switch...
Страница 146: ...146 Chapter 5 ActionScript Core Language Elements See also break continue while...
Страница 229: ...while 229 i 3 The following result is written to the log file 0 3 6 9 12 15 18 See also do while continue for for in...
Страница 808: ...808 Chapter 7 ActionScript for Flash...
Страница 810: ...810 Appendix A Deprecated Flash 4 operators...
Страница 815: ...Other keys 815 Num Lock 144 186 187 _ 189 191 192 219 220 221 222 Key Key code...
Страница 816: ...816 Appendix B Keyboard Keys and Key Code Values...
Страница 822: ...822 Index...