Author Topic: xmlDOM Example in VB  (Read 3540 times)

dcocks

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
xmlDOM Example in VB
« on: May 10, 2019, 07:12:41 am »
Does anyone have a simple example of VB code that can be used to pass XML to a template fragment for document generation? The only example in the help files or white paper is JScript and, evidently, I am not converting it correctly.

Is it required that I use a XML DOM data structure? I am not familiar with them and cannot find help on the operations they offer to know how to properly invoke them (Should oName and oID in the code below be attributes of Row or Elements under it?). I can easily create a VB String variable with the tags and values formatted like the sample in the documentation, but I have been unsuccessful in getting any document to use the template fragment that calls it.

The test script that I am currently using just attempts to create a single row that passes a Name and an ID attribute.

Code: [Select]
option explicit

!INC Local Scripts.EAConstants-VBScript

Function MySQL(objectID)

Dim xmlDOM

  set  xmlDOM = CreateObject("MSXML2.DOMDocument.4.0")

  xmlDOM.validateOnParse = False
  xmlDOM.async = False

  Dim node
  Set node = xmlDOM.createProcessingInstruction("xml", "version='1.0'")
  xmlDOM.appendChild node
 
  Dim xmlRoot
  Set xmlRoot = xmlDOM.createElement("EADATA")
  xmlDOM.appendChild xmlRoot

  Dim xmlDataSet
  Set xmlDataSet = xmlDOM.createElement("Dataset_0")
  xmlRoot.appendChild xmlDataSet

  Dim xmlData
  Set xmlData = xmlDOM.createElement("Data")
  xmlDataSet.appendChild xmlData

  Dim xmlRow
  Set xmlRow = xmlDOM.createElement("Row")
  xmlData.appendChild xmlRow

  dim oName
  set oName = xmlDOM.createAttribute("sName")
  oName.NodeValue = "Sample Name"
  xmlRow.setAttributeNode (oName)
 
  dim oID
  set oID = xmlDOM.createAttribute("sID")
  oID.NodeValue = "2456"
  xmlRow.setAttributeNode (oID)

  MySQL= xmlDOM.XML
 
End Function
« Last Edit: May 10, 2019, 08:18:28 am by dcocks »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13387
  • Karma: +566/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller

dcocks

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: xmlDOM Example in VB
« Reply #2 on: May 11, 2019, 08:57:58 am »
Thanks. These were helpful. I got my code working.