help populating MS DOM using visual basic 6

Neil Evans-Mudie nevansmu at fdgroup.co.uk
Mon Apr 19 11:02:09 BST 1999


subject: help populating MS DOM using visual basic 6

Hi,

i'm new to the xml development scene and have been trying to get up to 
speed. I develop using VB6 and wish to populate MSXML's DOM using an ADO2 
recordset (rs). I can then just call the DOMDocument.XML method to create 
my tagged up XML string - perfect. Unfortunately i can't work out how to 
populate the DOM tree. The code following creates the rs and then writes to 
textbox control my vision of what the XML should look like (also follows). 
[MDB file supplied as attachment, place in same folder as vb form!]

can anybody please advise me how to fill the DOM tree? Many thanks in 
advance for any suggestions given. Thanks also for the discussions on the 
list - they're excellent for newbies, like me, learning about new 
technologies like XML (i know XMLs not new, but it mass implememntation 
seems to be just becomming fashionable).

Best wishes

Neil (signature below).


XML Vision
~~~~~~~~
Schools: Records = 2
	|
	+--- School
	|	|
	|	+--- ID: 1	
	|	|
	|	+--- Name: Ballerkermeen High School	
	|
	+--- School
	 	|
	 	+--- ID: 2	
	 	|
	 	+--- Name: St. Ninians High School	

Code
====
Private Sub Form_Load()

  Dim cnn As ADODB.Connection, rs As ADODB.Recordset
  Dim dmdoc As New msxml.DOMDocument
  Dim nIndex As Integer, nTabNum As Integer
  Dim sSQL As String, sChara As String, s As String

  On Error GoTo Err_Hand_Control

  Set cnn = New ADODB.Connection: Set rs = New ADODB.Recordset
  cnn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & _
      App.Path & "\Help.mdb"
  sSQL = "Select [ID], [Name] from [Schools] order by [Name]"
                                      '# open the recordset..
  rs.Open sSQL, cnn, adOpenStatic, adLockReadOnly, adCmdText

  '# insert code to populate doc. object model then send to textbox in UI
  '# txtXML.Text = dmdoc.xml             '# set textbox to xml of DOM.XML 
contents

  '# this code snippet produces txt description of rs as a tree
  s = "Schools: Records = " & rs.RecordCount & vbCrLf
  nTabNum = 1
  Do While Not rs.EOF                 '# whilst recs to process..
    rs.MoveNext
    sChara = IIf(rs.EOF, " ", "|")
    rs.MovePrevious
    s = s & String(nTabNum, vbTab) & "|" & vbCrLf
    s = s & String(nTabNum, vbTab) & "+--- School " & vbCrLf
    For nIndex = 0 To rs.Fields.Count - 1
      s = s & String(nTabNum, vbTab) & sChara & vbTab & "|" & vbCrLf
      s = s & String(nTabNum, vbTab) & sChara & vbTab & "+--- " & _
        rs.Fields(nIndex).Name & ": " & rs.Fields(nIndex).Value & vbTab & 
vbCrLf
    Next nIndex
    rs.MoveNext                       '# next record
  Loop
  Text1.Font = "Courier"              '# set non-proportional font
  Text1.Text = s                      '# update UI with fake DOM tree
  '# CLose ADO OBJs..
  rs.Close: Set rs = Nothing
  cnn.Close: Set cnn = Nothing
  DoEvents                            '# yield execution
  Exit Sub                            '# avoid error handler

Err_Hand_Control:
  With Err
    MsgBox .Number & ": " & .Description, vbOKOnly, "Unexpected error.. 
closing app. "
  End With
  End                                   '# close app
End Sub

=======

Neil Evans-Mudie
Developer, fretwell-downing group Ltd.
(nevansmu at fdgroup.co.uk; http://www.fdgroup.co.uk/)
[Snail-Mail:
fretwell-downing group Ltd,
Brincliffe House, 861 Ecclesall Road, Sheffield, S11 7AE, England.
Tel:   +44 (0)114 281 6000; Fax:   +44 (0)114 281 6001]


-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/octet-stream
Size: 65536 bytes
Desc: not available
Url : http://mailman.ic.ac.uk/pipermail/xml-dev/attachments/19990419/475e4fe6/attachment.obj


More information about the Xml-dev mailing list