tailieunhanh - Using the XML Class

Sử dụng Class XML Đó là thời gian để bắt đầu sử dụng một số XML! Gần như tất cả mọi thứ bạn làm với XML trong Flash bao gồm các lớp học XML và thuộc một trong các loại sau: định dạng XML, phân tích cú pháp XML (chiết xuất thông tin), bốc XML, hoặc gửi XML. | Using the XML Class It s time to start using some XML Nearly everything you do with XML in Flash involves the XML class and falls into one of the following categories formatting XML parsing XML extracting the information loading XML or sending XML. With the XML class you can load XML from an external source such as a static file or a server-side script. After an XML document is loaded you can access its information using the methods and properties of the XML class. You can also use the methods and properties of the XML class to create your own XML document. After this document is created you can use it in a Flash movie or send it out to a server-side script. This section covers the ActionScript you need to accomplish these goals. Formatting XML The XML class in Flash has several methods most of which you can use to create and format XML documents. The truth is though you re unlikely to employ them because they re difficult to use and there s a better way. We ll show you how to create a string and then convert it into an XML object a much easier and more common way of formatting XML objects. To create an XML object in Flash you must use the XML class constructor. Here s how you would create an empty XML object var myXML XML new XML To populate the object with XML-formatted data when it s created you can pass inside the parentheses of the constructor the name of a variable that holds an XML-formatted string or another XML object. Suppose you want to create the following XML document in Flash MyFriends Name Gender female Kelly Makar Name Name Gender male Free Makar Name MyFriends You would do two things 1. Create the document as a string. 2. Convert the string to an XML object by using the XML class constructor new XML . Here s an example var myString String MyFriends Name Gender female Kelly Makar Name Name Gender male Free Makar Name MyFriends var myXML XML new XML myString This code creates the XML document as a string and converts it to an XML object called myXML.