Flash reads XML files

Source: Internet
Author: User
The introduction and writing formats of XML are not discussed here (because everyone is smart ). The most common use of XML is to read the data stored in the XML document. Let's create the XML document to be read. You can use any plain text editor to create an XML document. Open your plain text editor and enter the following Code ;
(This is a personal resume ):

//////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// ///

<? XML version = "1.0" encoding = "gb2312"?>
<Personal>
<Profile>
<Name> Ming </Name>
<Sex> male </sex>
<Age> 21 </age>
<City> Nanning </city>
</Profile>
<Profile>
<Name> traditional </Name>
<Sex> male </sex>
<Age> 21 </age>
<City> Shanghai </city>
</Profile>
</Personal>

Save this document as profile. xml.
Now we will create a flash for reading the profile. XML document.Program. Create a new flash document and bind the following script to the 1st frames of the root timeline:

// Prevent garbled characters (this is generally the case, but you can delete this sentence as long as the XML document is saved in UNICODE)
System. usecodepage = true;
// Create an XML Object myxml
Myxml = New XML ();
// Create an array of all and aa bb cc dd
VaR all = new array ();
VaR AA = new array ();
VaR BB = new array ();
VaR cc = new array ();
VaR dd = new array ();
// Load profile. xml into myxml
Myxml. Load ("profile. xml ");
// Ignore only blank text nodes
Myxml. ignorewhite = true;
// Processing that should be performed when profile. XML is fully loaded into myxml
Myxml. onload = function (SUCCESS ){
// If profile. XML is fully loaded
If (SUCCESS ){
// Obtain the object array of all child node objects in the myxml object. Each Data Element in the object array is a child Node object in the myxml operation object.
All = myxml. firstchild. childnodes;
// You can see "<personal> <profile> ..... </profile> <profile> ..... </profile> </personal> "all data
Trace (all );
// Use one for to get the total number of all. Here 2
For (VAR I = 0; I <all. length; I ++ ){
// If You Want To obtain all the "<Name>... </Name>" data in the profile. xml file, enter the following sentence
AA [I] = All [I]. childnodes [0]. firstchild. nodevalue;
Trace (AA [I]);
// If You Want To obtain all the "<sex>... </sex>" data in the profile. xml file, enter the following sentence
Bb [I] = All [I]. childnodes [1]. firstchild. nodevalue;
Trace (BB [I]);
// If You Want To obtain all the "<age> .. </age>" data in the profile. xml file, enter the following sentence
CC [I] = All [I]. childnodes [2]. firstchild. nodevalue;
Trace (CC [I]);
// If You Want To obtain all the "<city>... </city>" data in the profile. xml file, enter the following sentence:
Dd [I] = All [I]. childnodes [3]. firstchild. nodevalue;
Trace (Dd [I]);
} // End

//////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// ////////
/////////// ///// //
// Syntax: myxml. childnodes
// return: an array of objects
// Description: Read the childnodes attribute of the XML operation object, you can obtain an array of objects containing all the child node objects in the myxml operation object. Each Data Element in the object array is a child Node object in the myxml operation object.
/// // syntax 2 ///// /// //
// Syntax: myxml. firstchild
// return: an XML element or text Node object
// Description: Read the firstchild attribute of the XML operation object, you can obtain the first child element node or child text Node object contained in the myxml operation object.

Is it easy! Of course, this is just our preliminary step. After that, I will explain how to use the data in the XML document to create a simple Flash Player.

Article2 ==================================

XML class:
XML. ignorewhite; // process the white space in the XML document. If it is set to true, the white space is ignored. The default value is false.
XML. Load ("XML document address"); // load the specified XML document.
XML. onload = function (success: Boolean) {}; // called when the XML document is successfully loaded.
XML constructor.

Xmlnode class:
Xmlnode. attributes; // used to specify the attributes of an XML document.
Xmlnode. childnodes; // returns the child-level array of the specified XML Document Object.
Xmlnode. firstchild; // reference the first child in the Child list of the parent node.
Xmlnode. nodevalue; // return the node value of the XML object.
Xmlnode. nodename; // node name of the XML Object

Find these attributes in "Blue ideal" and try nodevalue for a long time, but still fail...

On the Rise, I tried firstchild and succeeded ..

For example, <XML> <ls> <langshen name = "langshen"> or langshen </langshen> </ls> </XML>

The name is extracted as follows when the value "langshen" in an XML file is extracted:

XML. firstchild. Attributes. Name

The node content is:

XML. firstchild .. If nodevalue is used, null is returned.

In addition, the first layer is already a firstchild when reading XML in Flash is different from the VB class...

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.