' This procedure creates XML document
' and saves it to disk.
' Requires msxml.dll (Go to Project --> References and
' and choose Microsoft XML version 2.0, or whatever the
' current version you have installed)
' The example given below will write the following XML
' documents.
'
' <Family>
' <Member Relationship="Father">
' <Name>Some Guy</name>
' </member>
' </family>
'
'but it should be clear how to modify the code
'to create your own documents
Private Sub Create_XML()
Dim objDom As DOMDocument
Dim objRootElem As IXMLDOMElement
Dim objMemberElem As IXMLDOMElement
Dim objMemberRel As IXMLDOMAttribute
Dim objMemberName As IXMLDOMElement
Set objDom = New DOMDocument
' Creates root element
Set objRootElem = objDom.createElement("Family")
objDom.appendChild objRootElem
' Creates Member element
Set objMemberElem = objDom.createElement("Member")
objRootElem.appendChild objMemberElem
' Creates Attribute to the Member Element
Set objMemberRel = objDom.createAttribute("Relationship")
objMemberRel.nodeValue = "Father"
objMemberElem.setAttributeNode objMemberRel
' Create element under Member element, and
' gives value "some guy"
Set objMemberName = objDom.createElement("Name")
objMemberElem.appendChild objMemberName
objMemberName.Text = "Some Guy"
' Saves XML data to disk.
objDom.save ("c:\temp\andrew.xml")
End Sub