So far, you've probably heard of LINQ (Language Integration Query), which is the new query technology that comes with visual studio®2008. LINQ-enabled languages, such as visual basic®, provide you with a rich set of query operators that you can apply to a variety of data sources, such as in-memory collections, databases, datasets, and XML. This technology is already very good, but visual Basic 9.0 actually provides much more than that, making XML a first-class data type that is directly integrated into the language.
Now you may want to know why you need to integrate XML data types directly into Visual Basic. Today, many applications are using XML for storage and data transfer. XML is widely used in the industry because of its flexibility and simplicity, and it is also used for many applications that perform storage and data transfer functions. Because XML is self-describing (that is, the structure of the data is included in the data), it is particularly suitable for transferring data between systems. Furthermore, it is much easier to read data that is constructed inside an XML tag than to write analysis rules for various custom file formats.
The problem with XML, however, is that developers have never been very easy to use it. Confusing and inconsistent APIs, such as the Document Object Model (DOM), and languages such as XSLT and XQuery, are often difficult to read and understand. But after the introduction of LINQ and Visual Basic 9.0, XML development has become much easier. In this column, you will explore the current XML programming experience, how LINQ improves the experience, and how Visual basic provides more support when working with XML.
Using the DOM
First, suppose you need to write out a list of customers in XML. My customer list has the following properties: FirstName, LastName, address, city, state, and ZipCode. When you convert a list to XML, it should look like Figure 1.
Customer List Properties in Figure1xml
<Customers>
<Customer FirstName="Jane" LastName="Dow">
<Address>123 Main St</Address>
<City>Redmond</City>
<State>WA</State>
<ZipCode>10104</ZipCode>
</Customer>
<Customer FirstName="Matt" LastName="Berg">
<Address>456 First St</Address>
<City>Seattle</City>
<State>WA</State>
<ZipCode>10028</ZipCode>
</Customer>
</Customers>