Loading XML data using ActionScript 3.0
Loading XML data using ActionScript 3.0
By Blue_Chi | Flash CS3 | ActionScript 3.0 | Beginner
Using XML is one of the best ways for structuring external content in a logical format that is easy to understand, process, and update. This tutorial will teach you the basics on how to load and process XML in Flash using ActionScript 3.0. You are assumed to have basic knowledge of ActionScript in order to follow this tutorial.
This tutorial is for working with XML in ActionScript 3.0. If you would like to learn how to work with XML in ActionScript 1/2 then please review our previous Flash XML tutorial.
Our tutorial will be divided into the following short sections:
What is XML?
Writing an XML File for Flash.
Loading XML in Flash.
Processing XML in Flash.
What is XML?
XML stands for Extensible Markup Language, it is a markup language used to structure data logically using tags that look very similar to HTML. However, when using HTML you use existing tags to create your web pages, but in XML you create you own tags which you later use in your program the way you choose. This makes it easy to create tags which are descriptive of your project and understandable by any human being. For example, you do not need any preliminary knowledge about XML or the program that uses it to figure out the purpose of the sample code below:
<?xml version="1.0" encoding="utf-8"?>
<GALLERY>
<IMAGE TITLE="school">image1.jpg</IMAGE>
<IMAGE TITLE="garden">image2.jpg</IMAGE>
<IMAGE TITLE="shop">image3.jpg</IMAGE>
</GALLERY>
As you just saw, XML makes it possible for authors to create and name their tags in whatever form they choose as long as they adhere to the basic rules of the language. Another main feature of any XML document is that the tags of an XML document define elements which are structured in a parent/child manner, where each tag may have a number of children tags but only one parent.
Moving on the actual content
Ïà¹ØÎĵµ£º
¿´½áÂÛÇëÖ±½Ó¿´ÏÂÃæ
½ñÌìдÉú³ÉxmlµÄphp¡£Ã»ÓÐÓÃʲôXMLDOMNodeÖ®ÀàµÄÀ´Éú³É£¬¶øÊÇÖ±½Óecho³öxmlµÄÄÚÈÝ¡£
xmlµÄÄÚÈÝÖÐÓÐÒ»²¿·ÖµÄÊý¾ÝÊÇ´ÓdbÖÐÑ»·È¡³öµÄ£¬ÎÊÌâ¾Í³öÔÚÕâ¡£ÎÒ·¢ÏÖÈ«²¿È¡³öÊý¾Ýʱ£¬¶ÔÓÚÉú³ÉµÄxml£¬simplexml_load_string·µ»Øfalse£¬¼´±íÃ÷Éú³ÉµÄxmlÊÇ·Ç·¨µÄ¡£
debugһϣ¬·¢ÏÖÈ¡³öÊý¾Ý¼ÓÒÔÏÞÖÆ limit 8 һϠ......
Ò»¡¢Îĵµ¶ÔÏóÄ£ÐÍ£¨DOM£©
¡¡¡¡DOMÊÇDocument Object Model£¨Îĵµ¶ÔÏóÄ£ÐÍ£©µÄ¼ò³Æ£¬ÊǶÔXMLÎĵµ½øÐÐÓ¦Óÿª·¢¡¢±à³ÌµÄÓ¦ÓóÌÐò½Ó¿Ú£¨API£©¡£×÷ΪW3C¹«²¼µÄÒ»ÖÖ¿çƽ̨¡¢ÓëÓïÑÔÎ޹صĽӿڹ淶£¬DOMÌṩÁËÔÚ²»Í¬»·¾³ºÍÓ¦ÓÃÖеıê×¼³ÌÐò½Ó¿Ú£¬¿ÉÒÔÓÃÈκÎÓïÑÔʵÏÖ¡£
¡¡¡¡DOM²ÉÓöÔÏóÄ£ÐͺÍһϵÁеĽӿÚÀ´ÃèÊöXMLÎĵµµÄÄÚÈݺͽ ......
ÒÑÖªÓÐÒ»¸öXMLÎļþ£¨bookstore.xml£©ÈçÏ£º
<?xml version="1.0" encoding="gb2312"?>
<bookstore>
<book genre="fantasy" ISBN="2-3631-4">
<title>Oberon's Legacy</title>
<author>Corets, Eva</author>
&nb ......
1 ÀàËÆxmlns=""µÄÎļþ
ʾÀýXMLÎļþ:
<?xml version="1.0" encoding="UTF-8"?>
<WebSrvMessage xmlns="http://www.lenoval.com/">
<version>1.0</version>
<DataContent>
<DateTag>2010-5-17</DateTag>
</DataCont ......
2010-05-16
Èý¡¢½âÎöXMLÎĵµ
l Xerces½âÎöÆ÷¡¢SAXÀàºÍ½Ó¿Ú
l SAXÔĶÁÆ÷
n Ê×ÏÈÒªµÃµ½Ò»¸ö·ûºÏSAX org.xml.sax.XMLReader½Ó¿Ú¹æ·¶µÄÀý×Ó£¬Õâ¸ö½Ó¿Ú¶¨ÒåÁ˽âÎöÐÐΪ²¢ÔÊÐíÉèÖÃijЩÌØÕ÷ºÍÊôÐÔ¡£¸Ã½Ó¿ÚÌæ»»ÁËSAX1.0ÖеÄorg.xml.sax.Parser
import org.apache.xerces.parsers.SAXParser;
import org.xml. ......