Load an XML tp rich text box

Karthikanbarasan
Posted by Karthikanbarasan under VB.NET category on | Points: 40 | Views : 4330
Public Sub LoadXMLtoBOX(ByVal strXMLPath As String)

Me.rtbTextbox1.Text = ""

Dim reader As New XmlTextReader(strXMLPath)
While reader.Read()
Select Case reader.NodeType
Case XmlNodeType.Element
'The node is an element.
Me.rtbTextbox1.SelectionColor = Color.Blue
Me.rtbTextbox1.AppendText("<")
Me.rtbTextbox1.SelectionColor = Color.Brown
Me.rtbTextbox1.AppendText(reader.Name)
Me.rtbTextbox1.SelectionColor = Color.Blue
Me.rtbTextbox1.AppendText(">")
Exit Select
Case XmlNodeType.Text
'Display the text in each element.
Me.rtbTextbox1.SelectionColor = Color.Black
Me.rtbTextbox1.AppendText(reader.Value)
Exit Select
Case XmlNodeType.EndElement
'Display the end of the element.
Me.rtbTextbox1.SelectionColor = Color.Blue
Me.rtbTextbox1.AppendText("</")
Me.rtbTextbox1.SelectionColor = Color.Brown
Me.rtbTextbox1.AppendText(reader.Name)
Me.rtbTextbox1.SelectionColor = Color.Blue
Me.rtbTextbox1.AppendText(">")
Me.rtbTextbox1.AppendText(vbLf)
Exit Select
End Select
End While
reader.Close()

End Sub



LoadXMLtoBOX(strXMLPath.ToString())

Comments or Responses

Login to post response