Create an XML Document Dynamically (Visual Basic)

MSXML 5.0 SDK

Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - DOM Developer's Guide

Create an XML Document Dynamically (Visual Basic)

You already know that you can create an XML document as an XML file using any text editor. However, it is often necessary to create an XML document or fragment dynamically in an application. For example, an application might need to output results in an XML format for downstream processing, or legacy data might need to be reformatted in XML.

In this project, we will show you how to create an XML document in memory. Specifically, we will demonstrate how to add processing instructions, comments, elements, and text nodes. We will also show how to use extra white space text nodes to provide a structured format when the DOM object is serialized.

This tutorial uses or creates the following files:

File Description
Source: dynamDOM.frm Visual Basic source code.
Output Output from the application.

To create the DynamDOM Visual Basic Project

  1. Create a Visual Basic project and set a reference to MSXML 5.0. For detailed instructions on how to do this, see Set Up My Visual Basic Project.
  2. Name the project DynamDOMProj.

Next, we’ll add the source code for this project.