[
Lists Home |
Date Index |
Thread Index
]
- From: nevansmu@fdgroup.co.uk (Neil Evans-Mudie)
- To: "'xml-dev@ic.ac.uk'" <xml-dev@ic.ac.uk>
- Date: Mon, 19 Apr 1999 10:03:03 +0100
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@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]
Help.mdb
|