I made a program to edit xml files, and it works great until an element like <Element />
appears. When it happens, all Elements after it don't show up on the treeview.
Here's my code for populating the array:
Public Function ReadXML() As String
Try
Dim iLevel As Integer = 0
Dim iIndex As Integer = 0
Dim oReader As XmlTextReader = New XmlTextReader(sFilePath)
Do While (oReader.Read())
Select Case oReader.NodeType
Case XmlNodeType.Element 'Display beginning of element.
If iIndex = 0 Then
ReDim aXML(0)
Else
ReDim Preserve aXML(iIndex)
End If
aXML(iIndex).Element = oReader.Name
aXML(iIndex).Layer = iLevel
iLevel += 1
iIndex += 1
Case XmlNodeType.Text 'Display the text in each element.
aXML(iIndex - 1).Text = oReader.Value
Case XmlNodeType.EndElement 'Display end of element.
iLevel -= 1
End Select
Loop
oReader.Close()
Catch ex As Exception
MsgBox("Ocorreu um erro" & vbCrLf & ex.Message)
cLog.WriteToErrorLog(ex.Message, ex.StackTrace, "Error")
End Try
Return ""
End Function
And here's the code for populating the treeview with the array.
Case ".xml"
Dim oRootNode() As TreeNode
Dim i As Integer
Dim iParent As Integer
Dim aParent() As String
ReDim aParent(0)
aParent(0) = i
tvw.Nodes.Add(aParent(0), cXML.ReturnElement(0))
oRootNode = tvw.Nodes.Find(aParent(0), True)
For i = 1 To cXML.ReturnLength - 1
If Not i = cXML.ReturnLength - 1 Then
Select Case cXML.ReturnLayer(i + 1)
Case Is > cXML.ReturnLayer(i)
iParent += 1
ReDim Preserve aParent(iParent)
aParent(iParent) = i
oRootNode = tvw.Nodes.Find(aParent(iParent - 1), True)
oRootNode(0).Nodes.Add(i, cXML.ReturnElement(i))
oRootNode = tvw.Nodes.Find(aParent(iParent), True)
Case Is = cXML.ReturnLayer(i)
oRootNode(0).Nodes.Add(i, cXML.ReturnElement(i))
Case Is < cXML.ReturnLayer(i)
oRootNode = tvw.Nodes.Find(aParent(iParent), True)
oRootNode(0).Nodes.Add(i, cXML.ReturnElement(i))
iParent -= 1
oRootNode = tvw.Nodes.Find(aParent(iParent), True)
End Select
Else
oRootNode(0).Nodes.Add(i, cXML.ReturnElement(i))
End If
Next
Any help would be apreciated.