This is a free tutorial to help beginning programmers get up to speed using Microsoft Visual Basic 2010 Express. To get the most from this tutorial, you might want to start at the beginning. A complete index to the course is also in the front of the first lesson.
Part 1 - A "From the Ground Up" Tutorial - An introduction to the course.
There's a whole world of data technology that we can't cover in a limited course like this one. I've selected two ways of accessing data: serializing to a file - featured in the previous lesson - and XML files. Using SQL to access databases isn't covered. I recommend trying the About.com "Databases" site for more.
In this segment of the tutorial, we continue to develop a more advanced version of the About Visual Basic Signature Block program. Although we used an XML file in the previous version, in this version we upgrade our use of XML.
Programmers have used EDI, parameter lists, .INI files, control strings, comma delimited files and a dozen other techniques to solve basically the same problem that we have in the Signature Block program: how to save a small collection of data between program executions. Today, almost all software technologies are in the process of converting to XML to do this, or have already converted to XML. (That's not an exaggeration. They really are.)
If this is your first introduction to XML, you might think it's complicated and technical. Although XML can become very technical, it's also possible to be elegantly simple and easy to understand. We're going to aim for "simple and easy" here but just to make sure you have a complete view of things, we're also going to use some of the more complicated methods.
If you want the final, authoritative word on XML, check out the site of the World Wide Web Consortium (W3C). The W3C is the standards body for all things XML and a growing body of satellite standards like schema, XSLT, XHTML and SOAP ... something we'll look at a little more later.
If you have ever looked at the HTML source code used in Web pages, then you have seen basically the same concepts used by XML that have made the Web one of the outstanding success stories of our age. An XML file is basically just a text file, like HTML, where the data in the file is identified by tags or strings of text that are used to identify the data. Tags are explained in more detail just a little later.
Traditionally, there were two ways that an XML file was processed. The DOM - the Document Object Model, which lets you process the whole XML document at one time, and SAX - Simple API for XML - which processes the XML as a stream of data much like a sequential file. These terms are falling out of fashion recently but you'll still run into them especially in academic articles and standards. In the new version of the Signature Block program, the data is processed using the DOM. The DOM fits in well with an ADO.NET concept, the DataSet because they both assume that all the data a program will need has been read from storage and is waiting to be processed.
Microsoft has now added one more: LINQ - Language INtegrated Query. LINQ isn't limited to just XML but it has powerful features for making XML much more accessible. We'll check out both the DOM and LINQ for accessing XML data in this segment.
The XML Advantage - Self Identifying Data
In the HTML language of a Web page, the information that displays on the page is identified with something that is often called a "tag". For example, if you want to give your Web page a title, you use the <title>My Web Page Title</title> tag. Because all operating systems can read simple text files and all browsers understand what the title tag does, any computer anywhere can interpret and use HTML. This completely universal compatibility is probably the biggest advantage of HTML.
XML does exactly the same thing, but instead of using only pre-defined tags like "title", "img" (image), and "p" (paragraph), you can invent your own tags. In the XML that we will use, I invented the tags FName, FNameChecked, and so forth for the Signature Block program. The big difference with XML is that if you invent your own tags, then you also have to write the code to process those tags. That's what we have been doing in the Signature Block program. With HTML tags, that programming to process the tags is built into your browser program.
Another advantage of XML is that it's readable by both humans and computers. This is actually very important. To see why, note that in the part 7 version of our program, we had to write a utility program to create the initial version of the serialized file because it was a binary file and it's only practical for a computer to create the file. (It's a little hard to create a binary file with Notepad.) But with XML, you can use any text editor to create one, although there are many specialized XML editors available for more advanced applications.
One of the first things about a "standard" XML file that might seem mysterious is the XML declaration - the very first line of the file. There are a lot of technical things that can be done with an XML declaration, but for now, you can use a declaration exactly like this:
<?xml version="1.0" encoding="utf-8"?>
It will probably work for everything you will need. By the time you need anything more advanced, you will have learned enough to code one.
In this lesson, we're going to code the Signature Block program using XML in two ways: the old, relatively complicated way and the new, simple way using another technology called LINQ. Click to go on to the next page and let's get started!