tailieunhanh - Mastering Microsoft Visual Basic 2010 phần 7

Các thủ tục mới () được gọi là các nhà xây dựng lớp. Mỗi lớp có một constructor mặc định chấp nhận không có đối số, thậm chí nếu các lớp học không có một chương trình con mới (). Constructor mặc định này được gọi mỗi khi thực hiện một tuyên bố tương tự như sau: | 598 chapter 14 an introduction to LINQ XElement represents an XML element. XAttribute represents an attribute in an XML element. These objects can be used to access the document but also to create it. Instead of creating an XML document directly in your code you can use the XML helper objects and a structural approach to create the same document. A simple XML document consists of elements which may include attributes. To create a new XElement object pass the element s name and value to its constructor New XElement element_name element_value The following statement will create a very simple XML document Dim XmlDoc New XElement Books MsgBox You will see the string Books in a message box. This is a trivial yet valid XML document. To create the same book collection as we did earlier by using the helper objects insert the following statements in a button s Click event handler Dim doc _ New XElement Books _ New XElement Book _ New XAttnbute ISBN 0000000000001 _ New XElement Price _ New XElement Name Book Title 1 _ New XElement Stock _ New XAttribute InStock 12 _ New XAttribute OnOrder 24 _ New XElement Book _ New XAttribute ISBN 0000000000002 _ New XElement Price _ New XElement Name Book Title 2 _ New XElement Stock _ New XAttribute InStock 7 _ New XAttribute OnOrder 10 I ve added a twist to the new document to demonstrate the use of multiple attributes in the same element. The Stock element contains two attributes InStock and OnOrder. Each element s value can be a basic data type such as a string or a number or another element. The Price element is a decimal value and the Name element is a string. The Book element however contains three subelements the Price Name and Stock elements. The doc variable is of the XElement type. An XML document is not necessarily based on the XDocument class. The two basic operations you can perform with an XElement and XDocument object are to save it to a file and reload an XElement object from a file. The .

TỪ KHÓA LIÊN QUAN