
ADOBE FLASH MEDIA INTERACTIVE SERVER
Server-Side ActionScript Language Reference
118
3 Shows how to move a node by using the appendChild() method, by moving the root node from doc1 to doc2.
4 Clones the root node from doc2 and appends it to doc1.
5 Creates a new node and appends it to the root node of the XML document doc1.
var doc1 = new XML();
var doc2 = new XML();
// Create a root node and add it to doc1.
var rootnode = 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 = 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 = doc1.createElement("newbie");
clone.appendChild(newNode);
trace ("doc1: " + doc1); // output: doc1: <root><newbie /></root>
XML.attributes
my_xml.attributes
An object that contains all the attributes of the specified XML object. Associative arrays use keys as indexes, not
ordinal integer indexes that are used by regular arrays. In the
XML.attributes associative array, the key index is a
string representing the name of the attribute. The value associated with that key index is the string value associated
with that attribute. For example, if you have an attribute named
color, you would retrieve that attribute’s value by
using the color as the key index, as shown in the following code:
var myColor = doc.firstChild.attributes.color
Availability
Flash Media Server 2
Example
The following example shows the XML attribute names:
// Create a tag called 'mytag' with
// an attribute called 'name' with value 'Val'.
var doc = new XML("<mytag name=\"Val\"> item </mytag>");
// Assign the value of the 'name' attribute to variable y.
var y = doc.firstChild.attributes.name;
trace (y);// output: Val
// Create a new attribute named 'order' with value 'first'.
doc.firstChild.attributes.order = "first";
Commenti su questo manuale