Sunday 22 September 2013

Create XML with XML Document Object

option explicit
private xmlObj as Object  ' xml object
private xmlHead as object  ' xml node
private xmlNode as object  ' xml node
private xmlChildNode as object ' xml nodePrivate sub CreateXML
   set xmlObj = CreateObject("MSXML2.DOMDocument") ' dynamic xmlobject created
   if xmlObj is nothing then  ' if failed then exit procedure
        exit sub
  end if
  set xmlHead = xmlObj.createElement("Parent")  'first xml node created , head node
  set xmlNode = xmlObj.createElement("Child1")  ' xmlnode created, first child of head
  cal xmlHead.appenChild(xmlNode) ' set to child of head
  set xmlChildNode= xmlObj.createElement("Child1ofChild1")  ' xmlnode created
  call xmlNode.AppendChild(xmlChildNode)  ' set to first child of the first child of head
  set xmlChildNode= xmlObj.createElement("Child2ofChild1")  ' xmlnode created
  call xmlNode.AppendChild(xmlChildNode) ' set to second child of the first child of head
  set xmlNode = xmlObj.createElement("Child2") ' xmlnode created, second child of head
  call xmlHead.appenChild(xmlNode)  ' set to child of head
   set xmlChildNode= xmlObj.createElement("Child1ofChild2")  ' xmlnode created
  call xmlNode.AppendChild(xmlChildNode) ' set to first child of the second child of head
  set xmlChildNode= xmlObj.createElement("Child2ofChild2")   ' xmlnode created
  call xmlNode.AppendChild(xmlChildNode) ' set to second child of the second child of head
 debug.print xmlHead.documentElement.xml
 set xmlnode=nothing
set xmlchildnode=nothing
set xmlobj=nothing
End Sub

No comments: