.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Collections >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Load an XML to the rich text box

Posted By:Karthikeyan Anbarasan       Posted Date: January 01, 2011    Points: 15    Category: Collections    URL: http://www.dotnetspark.com  

Loading an XML to the rich text box
 

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())

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend