Flash reading XML is a required course for flash programming, which will be frequently encountered in the future flash programming career.
In fact, reading XML in Flash is very simple.
The following is a simple description of as2:
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 data2
Myname = myname. nextsibling;
Trace (myname. nodename); // The output data3childnodes [0] is equivalent to firstchild
VII. Appendix: used for testingCodeThe 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 );
}
};