Simple tutorial on FLASH calling XML data
Author: imagebear
1. Create an XML object:
Var myXML = new XML ();
Ii. Reference an XML file:
MyXML. load ("data. xml ");
3. Ignore spaces:
MyXML. ignoreWhite = true; // The default value is false.
4. Functions for processing XML objects:
MyXML. onLoad = function (success) {statements ;}
V. Content of the data. XML file
<Data1 name = "imagebear"> <data2 name = "mariger"> xiaoshandong </data2> <data3 name = "mariger3"> xiaoshandong3 </data3> </data1>
Vi. Return Value instance
1. myXML. childNodes [0] will return:
<Data1 name = "imagebear">
<Data2 name = "mariger">
Xiaoshandong
</Data2>
<Data3 name = "mariger3">
Xiaoshandong3
</Data3>
</Data1>
2. myXML. childNodes [0]. nodeName will return: data1
3. myXML. childNodes [0]. childNodes [0]. name will return: imagebear
4. myXML. childNodes [0]. childNodes [0] will return:
<Data2 name = "mariger">
Xiaoshandong
</Data2>
5. myXML. childNodes [0]. childNodes [0]. nodeName will return: data2
6. myXML. childNodes [0]. childNodes [1]. attributes. name will return: mariger3
7. myXML. childNodes [0]. childNodes [0]. childNodes [0]. nodeValue will return: xiaoshandong
8,
Var myName = myXML. firstChild. firstChild; trace (myName. nodeName); // output data2myName = myName. nextSibling; trace (myName. nodeName); // The output data3childNodes [0] is equivalent to firstChild.
VII. Appendix: code for testing. The XML file is shown in the figure above.
Var myXML = new XML (); myXML. load ("data. xml "); myXML. ignoreWhite = true; myXML. onLoad = function (success) {if (success) {// myArray = myXML. childNodes [0]; // trace (myArray. attributes. name); // trace (myXML. childNodes [0]. childNodes [1]. firstChild. nodeValue); // trace (myXML. firstChild); // trace (myXML. childNodes [0]. nodeName); // trace (myXML. firstChild. attributes. name); // trace (myXML. childNodes [0]. childNodes [1]. nodeName); // trace (myXML. childNodes [0]. childNodes [1]. attributes. name); // trace (myXML. firstChild. firstChild); // trace (myXML. firstChild. firstChild. nodeName); // trace (myXML. firstChild. firstChild. attributes. name); // trace (myXML. childNodes [0]. childNodes [0]. childNodes [0]. nodeValue); var myName = myXML. firstChild. firstChild; trace (myName. nodeName); myName = myName. nextSibling; trace (myName. nodeName );}};