' VB client building XML document
Dim oXML As MSXML.XMLDocument
Dim oroot As Object
tvwXML.Nodes.Clear
Set oXML = New MSXML.XMLDocument
oXML.URL = txtURL
Set oroot = oXML.root
BuildTree oroot, "
tvwXML.Nodes.Item(1).Expanded = True
Private Sub BuildTree(oElement As IXMLElement, _
sParentID As String)
Dim sNodeLabel As String
Dim sNodeKey As String
Dim oChild As IXMLElement2
Static iParentID As Integer
' This is used to generate sequential unique IDs.
' First check element type. If it's an element, we
' add it as a node. If it's just text, we add it as
' an extension to the parent's text.
If oElement.Type = XMLELEMTYPE_ELEMENT Then
sNodeLabel = BuildNodeLabel(oElement)
iParentID = iParentID + 1
sNodeKey = "Node-" & CStr(iParentID)
If (Not oElement.Parent Is Nothing) And (sParentID _
<> ") Then
tvwXML.Nodes.Add sParentID, tvwChild, sNodeKey, _
sNodeLabel
Else
tvwXML.Nodes.Add , , sNodeKey, sNodeLabel
End If
If Not (oElement.children Is Nothing) Then
For Each oChild In oElement.children
BuildTree oChild, sNodeKey
Next oChild
End If
ElseIf oElement.Type = XMLELEMTYPE_TEXT And sParentID _
<> " Then
tvwXML.Nodes(sParentID).Text = tvwXML.Nodes( _
sParentID).Text + ": " + oElement.Text
End If
End Sub
|