Home > Articles > Web Services > XML

Getting Started with VB 6 and XML

VB.NET provides a host of new features for working with XML, but you don't have to wait for VB.NET to get started. Microsoft's MSXML library can get you up and running now. This article explains how to get started using XML in Visual Basic 6. It provides several examples showing how you can use XML documents in VB 6 applications.
Like this article? We recommend

Like this article? We recommend

For more information on XML and Web Services, visit our XML and Web Services Reference Guide or sign up for our XML and Web Services Newsletter.

What Is XML?

Extensible markup language (XML) is a simple data storage language. It represents data using a series of straightforward tags that you can create in any way you like. It is text-based, so it takes more space than a binary data format or even a delimited format, but it is extremely easy to use and understand.

XML provides no features for manipulating data, and anyone who tells you otherwise is selling something. In contrast, true databases such as Access, Oracle, and SQL Server provide a host of powerful data selection and analysis features such as indexing, sorting, searching, relational integrity, and cross-table selection. XML just holds data.

In fact, XML has only one real advantage over previous forms of data representation: It is extremely simple. That may seem like a trivial benefit, but in this case it makes all the difference in the world.

XML's great simplicity makes it easy for almost any application to read and write data. That puts XML in a unique position to become the lingua franca of data exchange. Although different applications may support a variety of data exchange formats, soon they can all support XML. That means your programs can easily combine information produced under Windows, Mac OS, Linux, mainframes, and any other platform you can think of. Then you can easily load XML data into your program, analyze it, and produce output in portable XML format.

What Is XML Good For?

The previous paragraph might have tipped you off that XML is good for exchanging data between different applications. If all your corporate systems produce XML output, you can easily combine the data to provide company-wide analyses.

XML files are also good for making small databases. Not too long ago, programs used INI files to store configuration information, user preferences, and other small amounts of data. Then Microsoft introduced the system registry and said developers should no longer use INI files. Since then, support for INI files has been dwindling in Visual Basic. Unfortunately, the registry has several disadvantages. It's not a simple text file, so it's hard to read; it can become bloated when you install and remove many applications from your system; and if it somehow becomes corrupted, the registry can make your system unusable.

Putting configuration information in XML files prevents these problems. You can even mount XML files on a shared file system so users on different computers can share the data they contain—a proposition that is tricky at best using the registry.

ASP.NET, the successor to ASP, lets you build XML directly into a Web page to form a "data island." You can then attach data-bound controls directly to the data, and display information automatically.

You can certainly do without XML. Text files, the registry, and relational databases can do everything XML can do and more. XML just adds one more tool to your data storage and retrieval arsenal.

XML Syntax

XML syntax is extremely simple, with a few exceptions that I'm going to ignore in this article. XML documents are composed of nodes. You represent a node using open and closing tags that are very similar to the tags used by HTML. One big difference is that you get to define the tag names. For example, the following tags might represent a telephone number:


You don't need to declare the tag names anywhere; you can just start using them.

The start and end tags must have exactly the same name with the same capitalization. If the node begins with <Phone>, it must end with </Phone>—not </phone> or </PHONE>. One common mistake is to copy and paste the opening tag to use as a closing tag and then to forget the slash, like this:


A node can include attributes in its opening tag. Simply include the attribute name, an equals sign, and the attribute value enclosed in quotation marks. For instance, the following code gives a Phone node the attribute Type. In this example, the node's Type attribute has value WorkFax.

<Phone Type="WorkFax">987-654-3210<Phone>

If you don't need to include a value in a node, you can omit the closing tag and end the node with a slash before the closing bracket. For instance, the following code stores a phone number in the node's Number attribute, so it doesn't need separate start and end tags.

<Phone Type="WorkFax" Number="987-654-3210" />

XML documents have a tree-like, hierarchical structure. A document must have a single root data node that contains all the other data nodes. Each node can contain other nodes nested to any depth.

That's about all there is to XML syntax. Here's a small example document:

  <Entry Type="Personal">
    <Street>1234 Programmer Place</Street>
    <Phone Type="Home">354-493-9489</Phone>
  <Entry Type="Work">
    <Phone Type="Work">937-878-4958</Phone>
    <Phone Type="WorkFax">937-878-4900</Phone>

Note that similar nodes in the tree do not necessarily contain the same information. In this example, the first Entry node contains address information and a home phone number. The second entry contains no address information, and has Work and WorkFax phone numbers that are missing from the first Entry node.

The root node Addresses need not contain only one type of node, either. For an address book application, it might make sense for the root to hold only Entry nodes. In another application, they could be anything.

XML Tools

As you can see from the previous example, XML syntax is quite simple. So simple, in fact, that you could probably hack together an XML parser in only a few hours. Fortunately there's no real need to do that because XML tools are available on a wide variety of platforms, including Windows where you run your Visual Basic programs.

It is these tools, not XML itself, that add the power and complexity to XML. Different parsers let you load an XML document all at once or one node at a time in a forward-only view. Conversely, XML writers let you write out a complete document or build one a node at a time.

Document object model (DOM) parsers let you load, clone, rearrange, modify, and save XML files. They let you search for nodes with certain names or attributes, order the results, and iterate over the matching nodes. Although they are not as powerful as a true relational database, these features are quite useful.

XSD (XML schema definition) and other schema languages let you define the format of an XML file to ensure that the data makes sense. For example, an XSD file can prevent someone from entering a street address in a Zip code field. XSL (extensible stylesheet language) lets you define how to convert an XML document into another format such as an HTML page for viewing on a Web browser.

These tools are actually much more complex than XML itself so XML books spend a fair amount of time explaining them. For more information on these topics, see my book, Visual Basic.NET and XML (Wiley, 2002, http://www.vb-helper.com/xml.htm).

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information

To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.


Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.


If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information

Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.


This site is not directed to children under the age of 13.


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information

If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information

Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents

California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure

Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact

Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice

We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020