XML, Array, and Object processing-example discussion

Source: Internet
Author: User
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 );

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.