TAILIEUCHUNG - Professional ASP.NET 2.0 XML phần 8

về việc áp dụng các tính năng này trong một trang web mà còn thể hiện sự thực hành tốt nhất của việc sử dụng các tính năng này. Hướng tới đạt được mục tiêu này, chương này thảo luận và giới thiệu các tính năng sau đây: ❑ | Chapter 12 Category category2 new Category 2 Condiments Sweet and savory sauces relishes spreads and seasonings CategoriesList list new CategoriesList categoryl category2 XmlSerializer serializer new XmlSerializer typeof CategoriesList Textwriter writer new StreamWriter xmlFilePath Serialize the Category and close the Textwriter writer list File written successfully script html xmlns http 1999 xhtml head runat server title Serializing a Collection Object title head body form id form1 runat server div div form body html In this code two instances of the Category class are created and populated with appropriate values. They are then added to the CategoriesList collection object. After that the collection object is passed to the constructor of the XmlSerializer object as follows. XmlSerializer serializer new XmlSerializer typeof CategoriesList Figure 12-2 shows the resultant XML produced by the page. Deserializing XML The XmlSerializer class provides a Deserialize method that you can invoke to read an XML stream and use to create and populate objects. You can deserialize from a generic stream a TextReader or an XmlReader. The overloads for Deserialize are Object Deserialize Stream Object Deserialize TextReader Object Deserialize XmlReader Object Deserialize XmlReader String Object Deserialize XmlReader XmlDeserializationEvents Object Deserialize XmlReader String XmlDeserializationEvents The remaining parameters allow you to pass the encoding style and the XmlDeserializationEvents object to the deserialization process. 394 XML Serialization Figure 12-2 To deserialize a Category object from the file created in the previous example you can simply open a file stream instantiate an XmlSerializer and call Deserialize. The complete code is shown in Listing 12-12. Listing 12-12 Deserializing an XML File .

TỪ KHÓA LIÊN QUAN
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.