TAILIEUCHUNG - Học Actionscript 3.0 - p 43

Writing XML Writing XML You’ve already seen how to write XML when creating an instance of the XML class, but you may also have to write to the instance over time. For example, you may need to add to XML based on user input or as data changes. The majority of techniques for adding content to XML mirror the process of reading the data, except this time you’re assigning information to a node rather than retrieving it. In this section, you’ll re-create the data used throughout the “Reading XML” section of this chapter. For simplicity, we’ll create element nodes, text nodes, and. | Writing XML Writing XML You ve already seen how to write XML when creating an instance of the XML class but you may also have to write to the instance over time. For example you may need to add to XML based on user input or as data changes. The majority of techniques for adding content to XML mirror the process of reading the data except this time you re assigning information to a node rather than retrieving it. In this section you ll re-create the data used throughout the Reading XML section of this chapter. For simplicity we ll create element nodes text nodes and attributes in one example and build an XML instance as if we were writing it over time. In a real scenario you would not assemble XML in multiple steps in the same script. However assuming the premise that we re writing the object in stages will allow us to demonstrate the most common XML writing methods. Because we re intentionally writing the XML out of order to demonstrate methods like insertChildBefore that will alter the order of nodes we ll show the progress of the XML as we go. The code that follows can be found in the source file. For clarity only the last trace statement is used in the source file to show the final XML content but you can uncomment any trace along the way to see interim results. To begin we must have an XML instance and a root node so line 1 creates both. Note that when adding element nodes without content you must specify a self-closing tag so the XML remains well formed. As soon as you add content to a self-closing node ActionScript will replace it with balanced open and closing tags. For example we re initially adding book as the root node but after adding the next element node the root node will become book book . Line 2 demonstrates the simplest technique for creating both an element node and a text node. When assigning a value to a node if the node does not already exist it will be created. If you assign another element node to the new node a nested element .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.