Flash read XML instance tutorial

Source: Internet
Author: User

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 );
}
};

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.