Something. xml file:
<? Xml version = "1.0" encoding = "UTF-8"?>
<Questions>
<Question… = "The People's Republic of China..."/>
<Question something = "I need one more stamp..."/>
<Question something = "All the new computers..."/>
</Questions>
Use XML objects in Flash:
Var my_xml = new XML ();
Var idx = 0;
My_xml.ignoreWhite = true;
My_xml.onLoad = function (success ){
If (success ){
Trace (this. firstChild. childNodes [idx]. attributes. Th );
// Access the certain attributes of the question node.
}
};
My_xml.load ("something. xml ");
It is a pity to traverse and access xml! It does not have the length attribute, while the Array object does. We convert it into an Array:
Var my_xml = new XML ();
Var my_array = new Array ();
Var xmlLength = 0;
Var idx = 0;
My_xml.ignoreWhite = true;
My_xml.onLoad = function (success ){
If (success ){
While (this. firstChild. childNodes [xmlLength]) {
My_array.push (this. firstChild. childNodes [xmlLength]);
XmlLength ++;
}
Trace (my_array [idx]. attributes. Th );
// At this time, the method used to access the attributes of the object in the question node has changed.
}
};
My_xml.load ("question. xml ");
Let's look at the Object:
Var my_xml = new XML ();
Var my_obj = new Object ();
Var idx = 0;
My_xml.ignoreWhite = true;
My_xml.onLoad = function (success ){
If (success ){
My_obj = this;
Trace (my_obj.firstChild.childNodes [idx]. attributes. Th );
// The method used to access the attributes of the question node is exactly the same as that used for the XML object. However, once my_obj changes, my_xml also changes, and vice versa.
}
};
My_xml.load ("question. xml ");
In comparison, we recommend that you use Array.
Ps:"
"Soft carriage return (that is, some text editors such as the line break of sepy are a small hacker in Notepad), supported by Flash Player 7 and later versions.
It is a pity to traverse and access xml! It does not have the length attribute, while the Array object has
XML has a length attribute.
You can use
Myxml = new XML ();
Myxml. onLoad = function (success ){
If (success ){
Secxml = myxml. firstChild. childNodes;
L = secxml. length;
Trace (........)
.......
}
};
You can also directly output its length:
Trace (this. firstChild. childNodes. length );